W.Kurek
W.Kurek

Reputation: 309

How to insert date to MySQL from html input?

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?

Upvotes: 0

Views: 718

Answers (5)

satish kilari
satish kilari

Reputation: 728

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

Upvotes: 0

hunglevan
hunglevan

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

saira
saira

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

Devsi Odedra
Devsi Odedra

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

Niklesh Raut
Niklesh Raut

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

Related Questions