varchar and date help pls...
Posted: Tue Jul 12, 2005 6:57 am
so far i have this code for date
the code above works and is written to mysql as varchar...but changing the startdate properties to date will not write the right value of the form to mysql...i tried to click the submit button with the desired date, will prompt me that the process is successful...but the value written to my database is 0000-00-00 and not the date i supplied
Code: Select all
<?
if (isset($_POST['submit']))
{
$message = NULL;
if (empty($_POST['month']) || empty($_POST['day']) || empty($_POST['year']))
{
$sd = false;
$message .= 'no date<br>';
}
else
{
$sd = $_POST['month']."-".$_POST['day']."-".$_POST['year'];
}
if ($sd)
{
$query = "INSERT INTO sample(startdate) VALUES ('$sd')";
$result = @mysql_query($query) or die(mysql_error());
if ($result)
{
echo 'written to db';
exit();
}
else
{
$message .= 'no data written in the db';
}
mysql_close();
}
else
{
$message .= 'please try again';
}
}
if (isset($message))
{
echo '<font color=red>'.$message.'</font>';
}
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<? calendar(); ?>
<input type="submit" name="submit" value="submit" />
</form>