I am having trouble saving the date of birth in Mysql Db from Php registration form, what am I doing wrong?
Check.php
$month = $_POST[\'month\'];
You should
this query should do what you want without errors:
$month = $_POST['Birthday_Month'];
$day = $_POST['Birthday_day'];
$year = $_POST['Birthday_Year'];
$date = $year . "-" . $month . "-" . $day;
$query = "INSERT INTO users (FirstName,LastName,Phone,DOB) VALUES ( '" . $FirstName . "','". $LastName . "','" . $Phone . "','" . $date . "')";
mysql_query($query) or die(mysql_error());
EDIT : I saw that you try to fetch the wrong POST-vars! You fetched $_POST['day'] but you need to fetch $_POST['Birthday_day'] which is the name of your select-field
You are doing wrong in concating in mysql query.
$FirstName + "','"
above is wrong.
use it as below.
'". $FirstName ."',
Edit
$date = $year."-".$Month."-".$Day;
INSERT INTO users
(FirstName,LastName,Phone,DOB)
VALUES
( '". $FirstName ."','". $LastName ."','". $Phone ."','". $date ."')
Mysql query should be format like
mysql_query("INSERT INTO users(FirstName,LastName,Phone,DOB)VALUES ( '".$FirstName."','". $LastName . "','" . $Phone . "','" . $Year . "-" . $Month + "-" . $Day . '")");
As others guys are saying, why not using PDO or MySQLi?
Your code will be more simple to code, and your code can be maintained over the time with other newer versions of PHP (MySQL FUNCTION ARE DEPRECATED FROM PHP5.5), e.g :
<?php
$month = $_POST['month']; $day = $_POST['day']; $year = $_POST['year']; $dob = $_SESSION['dob'];
$_SESSION['dob'] = $day . "-" . $month . "-" . $year;
$stmt = $pdoconnect->prepare('INSERT INTO users(FirstName,LastName,Phone,DOB) VALUES (:firstname, :lastname, :phone, :dob)')
$stmt->execute(array(
'firstname' => $FirstName,
'lastname' => $LastName,
'phone' => $Phone,
'dob'=> $dob
));
echo "Successful Registration!";
?>
I include a solution for simplify DOB using session.
EDIT (adding how to use pdo_mysql) :
// $DNS contain host (mysql:host=localhost by default), the database name and MySQL port (port=3606 by default).
$dns = 'mysql:host=localhost;dbname=beathost_cms;port=3606';
// $user --> MySQL USER
$user = 'root';
// $pass --> MySQL PASSWORD
$pass = 'root*';
try {
$pdoconnect = new PDO($dns, $user, $pass);
$pdoconnect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
} catch (PDOException $e) {
die ('An error occured with MySQL: ' . $e->getMessage());
}