Page 1 of 1

hi how to insert date function

Posted: Mon Jun 30, 2008 4:46 am
by nsbaskar
hi

i designed one webpage it have year, month and date collumn . i desired to filled it in php .after the insertion it will not inserted in data base . other fields are come in to the data base any body can help me
i given the specific code now




$vuname=$_POST["uname"];
$vpass=$_POST["pass"];
$vcpass=$_POST["cpass"];
$vname=$_POST["name"];
$vfname=$_POST["fname"];
$vdob1=$_POST["txtYear"]."/".$_POST["txtMonth"]."/".$_POST["txtDay"];
echo "$vdob1";
$vemail=$_POST["email"];
$vraddr=$_POST["raddr"];
$vbaddr=$_POST["baddr"];
$vophone=$_POST["ophone"];
$vrphone=$_POST["rphone"];
$vmobile=$_POST["mobile"];
$vfax=$_POST["fax"];
$vnob=$_POST["nob"];
$vref=$_POST["ref"];
$vvcode=$_POST["vcode"];
$con = mysql_connect("localhost","root","") or die(mysql_error());
$q="INSERT INTO esas_nuser VALUES (' ','$vuname','$vpass','$vcpass','$vname','$vfname','$vdob1',
'$vemail','$vraddr','$vbaddr','$vophone','$vrphone','$vmobile','$vfax',' $vnob','$vref',' $vvcode')";
mysql_select_db("esas",$con) or die(mysql_error());
mysql_query($q,$con);
mysql_close($con);

Re: hi how to insert date function

Posted: Mon Jun 30, 2008 5:52 am
by parimala
echo "$vdob1"; is wrong
echo $vdob1;

and if you want to insert a date inthe data base try to use now() function or mysql curdate() function is useful instead of giving 3 seperate fields

bye
have a nise day

Re: hi how to insert date function

Posted: Mon Jun 30, 2008 3:26 pm
by califdon
The previous reply was not helpful. It doesn't matter whether you use the double quotes or not. And it appears that you do not want the current date, but rather, a date input in a form.

Is the data type of your date field in the table Date or DateTime? If so, your format should work, since the manual states:
MySQL 5.0 Reference Manual - 10.3.1. The DATETIME, DATE, and TIMESTAMP Types wrote:As a string in either 'YYYY-MM-DD' or 'YY-MM-DD' format. A “relaxed” syntax is allowed here, too. For example, '98-12-31', '98.12.31', '98/12/31', and '98@12@31' are equivalent.
What is being echoed by your statement? Does it conform to the formats above?