Form Action - PHP function?
Moderator: General Moderators
Form Action - PHP function?
I am writing a form that will create a user in my application. I have a page called AddUser,php which contains the form. I want the php code that I use to check the input and store in the database to be on this same page, but I have no idea how to do it. I set the form action to "AddUser.php" but it ended up creating a blank entry in my database in addition to the submitted info. I tried adding an onclick on the submit button that would call a php function on that page but that didn't work either. A friend told me to use a hidden input field to accomplish this, but is there an easier way?
Re: Form Action - PHP function?
Did u keep the inserting part in an if condition? I guess not. Maybe thats the reason why a blank entry is inserted in your database.
if($_SERVER['REQUEST_METHOD']=="POST"){
//insert code
}
OR
if(isset($_POST['Submit'])){
//insert code
}
OR
if($_POST){
//insert code
}
if($_SERVER['REQUEST_METHOD']=="POST"){
//insert code
}
OR
if(isset($_POST['Submit'])){
//insert code
}
OR
if($_POST){
//insert code
}
Re: Form Action - PHP function?
Yes, thank you. It wasn't in an if statement 