PHP Date population trouble

#1

I am trying to get the date to display correctly in PHPMYAdmin as the correct date but all it shows is 0000-00-00. I know for sure there is a character off and it needs changed to something but I cannot figure it out for the life of me.

Here is the code and can someone show me why it wont work. What is wrong?? In this statement, why would it show the Date as 0000-00-00 instead of an actual date. For example it should read 2019-05-21 for example.

$sql=“UPDATE CreditTracker SET Approve=”$Approve",ClassWkshp=“ClassWkshp”,Sponsor="$Sponsor",Type="$Type",HrsUnits=“HrsUnits”,Date="$Date",$DateApproved WHERE idnum="$idnum"";

Why cant i get my date to show??

#2

Try this date_default_timezone_set(‘Europe/Paris’);
$date = date(“d F Y H:i:s”);

#3

And in my sql change row date in longtext,

#4

Yeah, no. That is not how you store dates.

1 Like
#5

It’s current date,you insert into mysql

#6

If you want just date,you put without H:i:s

#7

It seems like when I upgraded from php5 to php7 something broke. Seems tied to a single character.

#8

You need to run $sql,put mysqli_query($db,“Update your code here”);

#9

What does adding var_dump($Date) right before the sql statement show and where exactly is the $Date variable coming from?

Note: you should not put external/unknown data directly into an sql query statement. Use prepared queries instead. This actually simplifies your code, provided you are using the php PDO extension (you no longer need a bunch of different logic to make it safe to put all the different kinds of values into an sql query statement and it simplifies the sql query syntax.)

2 Likes
#10

That will show you exactly what is in the database and has nothing to do with PHP whatsoever.

You should be storing the date how the database expects it, and only change the formatting based on the view of the page that needs it.

#11

Great Gatsby this is incorrect. If this is what you should do, then please explain why there are date types?

2 Likes