Jump to content

Recommended Posts

hello, i'm sending date to mysql. when echoing the date in the browser, the date is correctly viewed.

$date=date("m.d.y");
echo $date;

 

but when sending to the database, its viewing there as 0's

is it a problem in the table in the db or the code itself

 

$sql = "INSERT INTO fooddiary (ID, Date, DayTime, FoodName, Calories)
VALUES ($clid, '$date', 'Breakfast', '$food', $cal)
ON DUPLICATE KEY UPDATE FoodName = '$food', Calories=$cal";
$result = mysqli_query($con, $sql) or die(mysqli_error());

other values are sent successfully!!
Link to comment
https://forums.phpfreaks.com/topic/278053-date-is-sent-00000000-to-mysql/
Share on other sites

Do NOT store dates as VARCHAR. You will not be able to use the mySql date functions, you will have problems with sorting and comparing, etc. etc.

 

Always store dates as DATE (or DATETIME or even TIMESTAMP). The server accepts and returns them as YYYY-MM-DD. You can change the way it displays when you retrieve the data.

 

Would you store numbers as "two hundred fifty-seven and 23/100" just so you can print it on a check? Of course not.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.