Jump to content

Problem Inserting Date


ChompGator

Recommended Posts

I have a script that users fill out a simple form > it inserts into the database, but the date field is not submitting into the database...Well it is submitted, except the date is being inserted into the database as all zeros in this format 00-00-0000.

 

Does anyone know why its submitting the date is submitting into my database in PHPMyAdmin like that?

In PHPMyAdmin I have selected as "Date" from the drop down for the date field.

Here is the script that inserts the values: Incase it helps

- Note, Im not getting any errors submitting the only problem is the script is submitting the date as 00-00-0000 into the table in phpmyadmin

 

<?php
$con = mysql_connect("","","");
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)
?>

Link to comment
https://forums.phpfreaks.com/topic/133452-problem-inserting-date/
Share on other sites

it means you $_POST['eventdate'] is not in the propper format.. i would do this instead

$sql="INSERT INTO cadet_events (eventname, eventdate, eventdescription)
VALUES
('$_POST[eventname]', NULL,'$_POST[eventdescription]')";

and then in your database change the type to timestamp and then under default check current timestamp so its filled in automatically

if you dont know much about timestamp just look up date() in the php manual

 

did that help at all?

Try some test queries with fake data:

INSERT INTO cadet_events
(eventname, eventdate, eventdescription)
VALUES
('testEvent','2008-11-20','A test event');

^-- Then check if mysql accepted it.  If this works, the problem lies with your form.  Post your form code, as well the php validation for the inputs.

 

The format (at least for my date col) defaults to YYYY-MM-DD, so be sure you're supplying that in your form.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.