Ivan Pandžić
Ivan Pandžić

Reputation: 373

Updating date field in database inserts all zero values

When code updates date field in database, the date becomes 0000/00/00. But when I print the date variable in web page with echo, output prints correct date. Any ideas how could update work.

Code:

$query=date('y/m/d');
$date="UPDATE student SET datum_upisa=$query WHERE _broj_indeksa='$broj_indeksa'";
mysqli_query($con,$date);

Upvotes: 3

Views: 576

Answers (3)

Mudassir Hasan
Mudassir Hasan

Reputation: 28751

$date="UPDATE student SET datum_upisa='$query' 
       WHERE _broj_indeksa='$broj_indeksa'";

When you use $query instead of '$query' , MySql is not able to parse a literal string $query to date type and silently converts to a zero value.

Upvotes: 1

Linga
Linga

Reputation: 10563

You have to use '$query' instead of $query

$date="UPDATE student SET datum_upisa='$query' WHERE _broj_indeksa='$broj_indeksa'";

Upvotes: 4

Manoj Purohit
Manoj Purohit

Reputation: 3453

use quote for date, change this line

$date="UPDATE student SET datum_upisa='$query' WHERE _broj_indeksa='$broj_indeksa'";

Upvotes: 4

Related Questions