Evrytime I was trying to enter the date into my
Database I was getting the date there 00-00-0000
What can I do so it would set the date on the database?
By the way my the date on the visitors table is “DATE” type.
<?php
$mysql_link = mysql_connect(*************) or die("ERROR 001: Cannot connect to MySQL server. please contact system administration.");
if (!mysql_select_db(********* $mysql_link))
echo "Could not select DataBase.";
$result = mysql_query("SELECT date,count FROM visitors");
echo date('j-n-Y');
$date=date('j-n-Y');
$count = 0;
while ($row = mysql_fetch_array($result))
{
if (strpos(date('Y-n-j'),$row['date'])!== FALSE)
{
$count = $row['count'] + 1;
break;
}
}
if ($count !== 0)
mysql_query("UPDATE visitors SET count=".$count." WHERE date=".$date);
else
{
$count = 1;
mysql_query("INSERT INTO visitors (date, count) VALUES ('".$date."','".$count."')");
}
?>
Edit:
What is the best way to insert date to database so I could read from database like that:
"SELECT … FROM … BETWEEN date1 AND date2