udaikr Posted November 10, 2013 Share Posted November 10, 2013 hello friends i am new in php ,want to add form with database ,but a error appeared , ( ! ) Notice: Undefined variable: name in C:wampwwwyour_mailregister.php on line 26 Call Stack # Time Memory Function Location 1 0.0521 142664 {main}( ) ..register.php:0 ( ! ) Notice: Undefined variable: email in C:wampwwwyour_mailregister.php on line 26 Call Stack # Time Memory Function Location 1 0.0521 142664 {main}( ) ..register.php:0 this is my code can anyone help me. if(isset($_POST['name'])){ $name = $_POST['name']; $email = $_POST['email']; $password = $_POST['password']; } $query = "INSERT INTO users (id,name,email,password,added_date,modified_date,status) VALUES ('','$name','$email','$password','NOW()','','0') "; Link to comment Share on other sites More sharing options...
Ingolme Posted November 10, 2013 Share Posted November 10, 2013 The variables are only being set if $_POST['name'] is set. Since $_POST['name'] isn't set, there's an error when trying to use those variables. Link to comment Share on other sites More sharing options...
udaikr Posted November 11, 2013 Author Share Posted November 11, 2013 I used isset in this code but it appears ,why ,i am confused with the use of isset can you please explain. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 11, 2013 Share Posted November 11, 2013 You get the variables only if they are set in $_POST. You always run the query though. So if the variables are not set then you will run the query with missing variables. Either put the query inside the if statement also so that you only run the query if the variables are set, or if you want to run the query even when the variables are not in $_POST then give $name, $email, and $password default values if they aren't in $_POST. Link to comment Share on other sites More sharing options...
Sora Posted November 11, 2013 Share Posted November 11, 2013 Put the query within the curly brackets. It would work without isset by the way. Link to comment Share on other sites More sharing options...
udaikr Posted November 12, 2013 Author Share Posted November 12, 2013 thanks Link to comment Share on other sites More sharing options...
es131245 Posted November 13, 2013 Share Posted November 13, 2013 (edited) offtopic but no need in empty brakets $query = "INSERT INTO users (name,email,password,added_date,status) VALUES ('$name','$email','$password','NOW()',,'0'); $query = "INSERT INTO users (id,name,email,password,added_date,modified_date,status) VALUES ('','$name','$email','$password','NOW()','','0') " Edited November 14, 2013 by es131245 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now