Jump to content

Error in database


udaikr

Recommended Posts

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

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

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 by es131245
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...