hi i have inserted the date value into the database but its showing as

0000-00-00

why like this can anybody help me whats the correct format to insert date
from a drop down list to the database ;
heres my code to handle this :

<?php
include("dmy.php");
echo "<Html><Head></Head>";
$setdate = date("Y-m-d");
if($sdd == "")
{
    $sddval = substr(date("Y-m-d"),8,2);
}
else
{
    $sddval = $sdd;
}
if($sdm == "")
{
    $sdmval = substr(date("Y-m-d"),5,2);
}
else
{
    $sdmval = $sdm;
}
if($sdy == "") 
{
    $sdyval = substr(date("Y-m-d"),0,4);
}
else 
{
    $sdyval = $sdy;
}
echo "<Form method=\"POST\" Name=\"MIS\" Action=\"get.php\">";
        generateDMY("sdd","sdm","sdy","$sddval","$sdmval","$sdyval","1950","MIS");
        echo "<br>";
        echo "<Input Type=\"Submit\" Name=\"Submit\" Value=\"SUBMIT\"></Form>";

echo "</Html>";

?>

this generates the date

now how to write the php script to insert the date value into the database

Recommended Answers

All 3 Replies

That means you are submitting it in the wrong format. If you are trying to put the current date in the use mysql's NOW() function to do it for you. It will be faster, always correct, and less code, too.

Otherwise echo out the date you are trying to insert as it clearly is in an incorrect format.

I've been using a code snippet from PHP.net's comments page on date formatting to do what NOW() does. I might just be rewriting some queries to take advantage of NOW(), rather than that function.

Thanks John. (Amazingly useful things those databases are, even if the query language leaves A LOT to be desired.)

No prob. :) A good rule of thumb is to do as much work at the database level as possible. It's faster and usually results in less code for you to work with in PHP. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.