necrofish666 necrofish666 - 4 months ago 9
SQL Question

Can't update Date field in MySql using PHP

I have a DATE field in my table, and I'm trying to update it using the following code:

$query = mysqli_query($conn,$sql);
$todaydate = date("Y-m-d");
$sqlDate = date('Y-m-d', strtotime($todaydate));
$sql="UPDATE Library SET Loaned=1, LoanedDate=$sqlDate WHERE BookId=$bookId";
$query = mysqli_query($conn,$sql);


It updates the "Loaned" field fine, but always sets the Date field to "0000-00-00". Can anyone indicate what I'm doing wrong?

Answer

Youre missing ' quotes in your update query

Just use something like this

$sql="UPDATE Library SET Loaned=1, LoanedDate='$sqlDate' WHERE BookId='$bookId'";
$query = mysqli_query($conn,$sql);
Comments