Reputation: 309
I've problem with inserting a date enter code here
into a MySQL database. On my webpage i've got a input which type is 'date' but there is a problem with inserting value of this input into database properly.
$connection->query("INSERT INTO users VALUES(NULL, '$nick', '$password_hash', '$email',".$_POST['gender'].",".$_POST['bday'].")")
Have you got any solution for my problem?
Upvotes: 0
Views: 718
Reputation: 728
$connection->query("INSERT INTO users VALUES(NULL, '$nick', '$password_hash', '$email','".$_POST['gender']."','".$_POST['bday']."')")
Upvotes: 0
Reputation: 109
You incorrect syntax of MySQL
$connection->query("INSERT INTO users VALUES(NULL, '$nick', '$password_hash', '$email',".$_POST['gender'].",".$_POST['bday'].")")
Correct syntax
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
Link refe: http://www.w3schools.com/php/php_mysql_insert.asp
I hope help you
Upvotes: 0
Reputation: 23
try this code, single quotes around the variables and I don't see the need of writing $_POST[], because you can access the variables simply by using their name
$connection->query("INSERT INTO users VALUES(NULL, '$nick', '$password_hash', '$email','$gender,'$bday'"));
Upvotes: 0
Reputation: 5322
Use this code. you forget Single quote (').
$connection->query("INSERT INTO users VALUES(NULL, '$nick', '$password_hash', '$email','".$_POST['gender']."','".$_POST['bday']."')")
Upvotes: 1
Reputation: 34914
Use single quotes around date value and using column name is good practice
$connection->query("INSERT INTO users VALUES(NULL, '$nick', '$password_hash', '$email','".$_POST['gender']."','".$_POST['bday']."')")
Upvotes: 1