hi how to insert date function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nsbaskar
Forum Newbie
Posts: 6
Joined: Thu Jun 26, 2008 7:54 am

hi how to insert date function

Post 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);
parimala
Forum Newbie
Posts: 8
Joined: Wed Jun 11, 2008 7:21 am

Re: hi how to insert date function

Post 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
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: hi how to insert date function

Post 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?
Post Reply