Detecting post versus first load
Posted: Fri Apr 07, 2006 5:12 pm
Hi all,
Hopefully this is the right section for this. I did a search for postback but couldn't find a response pertaining to my question.
I'm just starting with PHP (coming from an asp.net background). I created a simple form that inserts a record into a MySQL database. It works fine but when the page first loads it will insert a record of blank values (since the POST variables don't exist yet). How do I keep this from happening? I considered using a hidden input called "firstload" with a value of true, when the page is loaded the PHP script first checks an if statement to see if the firstload value is true, if not then it is parsed for the record insert. So I would just switch the value of "firstload" to false so the if statement returns false and the insert script is ran. I guess I should mention that the page is posting back to itself. However this solution seems like a cludge, and posting to different page shouldn't be necessary, or is it?
Thanks,
Justin
Hopefully this is the right section for this. I did a search for postback but couldn't find a response pertaining to my question.
I'm just starting with PHP (coming from an asp.net background). I created a simple form that inserts a record into a MySQL database. It works fine but when the page first loads it will insert a record of blank values (since the POST variables don't exist yet). How do I keep this from happening? I considered using a hidden input called "firstload" with a value of true, when the page is loaded the PHP script first checks an if statement to see if the firstload value is true, if not then it is parsed for the record insert. So I would just switch the value of "firstload" to false so the if statement returns false and the insert script is ran. I guess I should mention that the page is posting back to itself. However this solution seems like a cludge, and posting to different page shouldn't be necessary, or is it?
Thanks,
Justin