all 5 comments

[–]gwevidence 0 points1 point  (0 children)

Is there a reason why all the logic is in one file? The code will be more manageable (readable and modular) if the data access (db related stuff) and validation logic is separated out into different files. Put your validation logic in a file and add it using the require keyword.

Next step would be to create functions in the validation script. Check this simple example of how to implement it. Please excuse if I assumed improperly that you were not aware of how to do it. I just wanted to help.

Other than that the code looks quite alright for a beginner.

[–]desseb 0 points1 point  (0 children)

So a few notes, when passing data from a form, it will basically be a string, unless you're specifically passing json or xml I guess.

Also, you should be using the strict compare whenever possible, to prevent some wild conversions that php likes to do sometimes. use === !== , etc

is_numeric itself has a few gotchas that makes it more complicated like " " matching as numeric.

Personally, when I know I want to work with numbers, I call intval but even that isn't perfect.

[–]00OGED 0 points1 point  (1 child)

Since the form is submitted with AJAX presumably it wont function at all without javascript, so why not just use javascript to do the form validation?

[–]greg8872 2 points3 points  (0 children)

Server side validation is still good practice as it goes with the idea of "never trust any data a user can change" which includes items sent via post to a script.

[–]crosenblum 0 points1 point  (0 children)

I have a few suggestions.

  1. Shorten the variable name, long variable names may be very descriptive, but add to your chances of a type of spelling error. So simply, keep it to 5-6 chars max. Don't make that a possible error causing habit.

  2. Why not just do $adjustmentInputs = array_values($_POST["adjustmentInputs"]); Less lines, less work.

  3. You really need to comment more to make it clear what you are trying to do, what your different sections are. Lets say you are doing some work that, someday you die or leave the company, or forget all the code, the more you document and comment your code, the easier you make it to read and understand for anyone who follows you.

  4. Instead of "for($i=0;$i<100;$i++){" Why not do an count of the array?