Date into SQL

I’m having a bit of trouble inserting the following

if($ad_price == 10) { $renew = date(‘Y-m-d’, strtotime(’+6 months’)); }
if($ad_price == 20) { $renew = date(‘Y-m-d’, strtotime(’+1 year’)); }

$query_add = “INSERT INTO listings (renew_date)
Values (’$renew’)”;
$add = mysql_query($query_add, $connect) or die(mysql_error());

when the sql is set on date its entering 0000-00-00 when its set on text its entering -1900

I have tried echoing it to see if the outputs are ok and they are


<?php if($ad_price == 10) { $renew = date('d-m-Y', strtotime('+6 months')); } if($ad_price == 20) { $renew = date('d-m-Y', strtotime('+1 year')); } ?>
<?php echo $renew ?> [/php]

Does anybody have any suggestion

And you said you echoed out the dates you are creating and they come out as yyyy-mm-dd?

They have to be in that format in order for SQL to except them.

They’re not going i as text either. I have tried every conceivable way


Could you show the table, fields and field types your using and length of each.

I’ve just spottedthe error as I was copying the code here

I hadn’t encapsulated the string it was

insert into table (something) values ($something)


insert into table (something) values ('$something')

there are 30 or so variables in the insert so must have overlooked this one

Sponsor our Newsletter | Privacy Policy | Terms of Service