0

I've problem with inserting a date enter code hereinto 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?

2
  • Apart from the answers given, make sure your post is the same format as MySQL needs it (yyyy-mm-dd). If it's not, use PHP's date() function to change it. Commented Jul 23, 2016 at 11:32
  • Is your problem resolved with any of given answer below ? Commented Jul 23, 2016 at 11:40

5 Answers 5

1

Use this code. you forget Single quote (').

$connection->query("INSERT INTO users VALUES(NULL, '$nick', '$password_hash', '$email','".$_POST['gender']."','".$_POST['bday']."')")
Sign up to request clarification or add additional context in comments.

Comments

1

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']."')")

Comments

0

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'"));

Comments

0

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

Comments

0

$connection->query("INSERT INTO users VALUES(NULL, '$nick', '$password_hash', '$email','".$_POST['gender']."','".$_POST['bday']."')")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.