Page 1 of 1

MySQL Problem Inserting

Posted: Wed Nov 19, 2008 10:12 pm
by icepirates
I have a script that users fill out a simple form > it inserts into the database, but one field is not submitting
and that is the date. The date is just submitting into the database as 00-00-0000

The text box on the HTML form tells the user to submit the date as MM-DD-YYYY
And (Im the only one testing out the script right now, but I figured Id make it work before it goes live)

Does anyone know why its submitting the date like that. In PHPMyAdmin I have selected as "Date" for that field.
Here is the script that inserts the values:

Code: Select all

 
<?php
$con = mysql_connect("","l","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("legion", $con);
 
$sql="INSERT INTO cadet_events (eventname, eventdate, eventdescription)
VALUES
('$_POST[eventname]','$_POST[eventdate]','$_POST[eventdescription]')";
 
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "The Event Has Been Added - Thank You";
 
mysql_close($con)
?>

Re: MySQL Problem Inserting

Posted: Thu Nov 20, 2008 1:39 am
by ramya123
You should insert date value in YYYY-MM-DD format since in phpMyadmin the default Date format is YYYY-MM-DD.

Re: MySQL Problem Inserting

Posted: Thu Nov 20, 2008 7:01 am
by icepirates
Thanks for the help...

Now when I submit the form, its saying

Error: Duplicate entry '0' for key 1

Any idea why that is?

Re: MySQL Problem Inserting

Posted: Fri Nov 21, 2008 12:09 am
by ramya123
Set Primary Key to Autoincrement

This might solve your Problem