MySQL Problem Inserting

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
icepirates
Forum Newbie
Posts: 6
Joined: Mon Aug 18, 2008 11:11 am

MySQL Problem Inserting

Post 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)
?>
ramya123
Forum Newbie
Posts: 13
Joined: Thu Sep 11, 2008 6:11 am

Re: MySQL Problem Inserting

Post by ramya123 »

You should insert date value in YYYY-MM-DD format since in phpMyadmin the default Date format is YYYY-MM-DD.
icepirates
Forum Newbie
Posts: 6
Joined: Mon Aug 18, 2008 11:11 am

Re: MySQL Problem Inserting

Post 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?
ramya123
Forum Newbie
Posts: 13
Joined: Thu Sep 11, 2008 6:11 am

Re: MySQL Problem Inserting

Post by ramya123 »

Set Primary Key to Autoincrement

This might solve your Problem
Post Reply