PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am semi-new to PHP and I found myself having trouble during some form validation. For some reason $_POST is not working. I tried echoing some values from it. Nothing. Not even an error when there is nothing posted. I know echo is working because I can print simple strings. However, say for example, I have a field named "foo" and the data is posted to the same page for validation. When I don't even check whether the form was submitted or loaded for the first time, I can't even get an error message to work with. Any help would be much appreciated.
Are you sure you are submitting your values through POST? Would you care to show the headers of the requests to verify this?
Secondly, you will get errors if you are using an uninitialized variable, however, your error reporting is either set to low, or display errors is disabled.
I can't even force an error. Like you said, I was trying to get an error for an uninitialized variable.
Due to security reasons, I'll have to obscure the code a bit (just names and fields but the functionality should be the same). I deleted a lot of stuff so I'm not sure if it's still valid XHTML but here it is stripped down. Granted I'm not echoing the posted data in the end, but this is a temporary means for debugging.
I receive errors for invalid syntax and using require_once() to include files that do not exist on the server. I've never had this problem of displaying errors.
gtr053 wrote:I receive errors for invalid syntax and using require_once() to include files that do not exist on the server. I've never had this problem of displaying errors.
Those are both fatal errors. How are you getting them both?
Regardless, that's probably why you are "suspecting" POST global is not working. If you tried my test in it's own file without any other code you'll likely find it works correctly.
As for error displaying, it's completely up to the server configuration... which can vary from installation to installation.
John Cartwright wrote:Those are both fatal errors. How are you getting them both?
I don't get those errors now, but I would get them on the same server due to typos in previous development. The odd indentation you see in my HTML is caused by including other PHP files (for easy layout changes).
John Cartwright wrote:Regardless, that's probably why you are "suspecting" POST global is not working. If you tried my test in it's own file without any other code you'll likely find it works correctly.
Nope.
John Cartwright wrote:Development environment should always include
Explain exactly what happens when you post that test script in a separate and blank file, open it, and submit the button.
I am not too sure what you meant by this.
It means you should always develop with error_reporting(E_ALL) and display_errors = 1. It's best to set these in your php.ini since any settings made in code will not take affect upon a fatal error.
I am simply getting no output. Nothing changes after submitting the form to itself. I added the two lines you recommended but I am seeing no difference.
Okay, so I took out the if statement from that block of code and regardless of whether anything has been posted it or not, I get what appears to be an empty array. Correct me if I am wrong.
I have had this form work before and all I think I changed since the last time it worked was the layout. I had a table in the form rather than a bunch of div elements.