ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button
  Using MySQL from PHP
Subject:   insertind date data into table
Date:   2009-03-04 22:02:35
From:   krishkrish
i have a poblem in inserting data into table. i am puting dateof birth as select oprion as month, year,date. the user select this and post to table. but i create only date_of birth field as date data type. hoe i insert these there input into one field in table. please anybosy help me. the following coding only use. is ther eany error suggesstion please reply me.

// Connects to your Database
$host="localhost"; //Host Name
$username = " root"; //mysql user name
$password =" sivagami"; //mysql password
$db_name ="tms" ;//database name
$tbl_name ="employee" ; //Table Name

mysql_connect("localhost", "root", "sivagami") or die(mysql_error());
mysql_select_db("tms") or die(mysql_error());

$emp_id =$_POST('emp_id');
$emp_name =$_POST('emp_name');
$address =$_POST('address');

$bdayyear = $_POST['yyyy'];
$bdaymonth = $_POST['mm'];
$bdayday = $_POST['dd'];

$date_of_birth = " $bdayyear, $bdaymonth,$bdayday"; // or whatever format you want

// It would be printed as, for example ' December 22, 1987 ' Though you can change the format.

// When you insert the Bday into the mysql table, just use the $bdayfull variable

// $date_of_birth = $_POST('date_of_birth');
// $date_of_join =$_POST ('date_of_join');

$bdayyear = $_POST['yyyy'];
$bdaymonth = $_POST['mm'];
$bdayday = $_POST['dd'];

$date_of_join = " $bdayyear, $bdaymonth,$bdayday"; // or whatever format you want

$designation =$_POST('designation');

$sql ="INSERT INTO $tbl_name (emp_id, emp_name,address,date_of_birth,date_of_join,designation) VALUES ( '$emp_id', '$emp_name','$address','$phone','$date_of_birth', '$date_of_join','$designation' )"or die(mysql_error());

$result= mysql_query($sql) or die('Error updating database');
echo "successfull";