0

My problem is the following:

When DoExpressCheckout() is executed i have to save some data to Database, including the current time + X time

The type of the field of the database is set to "datetime"

I'm using the strtotime function in this way

date_default_timezone_set('Europe/Rome');

$currentTime = date("Y-m-d");

$expected = date('Y-m-d',strtotime($currentTime.'+ 7 days'));

echo $expected;

$sql = "INSERT INTO acquisti (durata,prezzi,expectedtime) VALUES (".$str.",".$resArray['AMT'].",".$expected.")";
echo $sql;
mysql_query($sql) or die("Errore di inserimento");

Here i have two problems:

1) The query always returns me error when putting the $expected variable into the expectedtime field 2) If i put it manually (just to try if i was stupid) it writes me 0000-00-00 (i've enabled the ALLOW_INVALID_DATES)

Any suggestions?

Thanks a lot

Glavić
  • 42,781
  • 13
  • 77
  • 107

2 Answers2

1

Your field type is 'datetime', but you are only sending date using the INSERT query.

You need to use date('Y-m-d H:i:s') instead of date('Y-m-d'), or if you need only the date change the type of the field to date.

Anil Saini
  • 627
  • 3
  • 17
0

Put values in enclosure:

$sql = "
    INSERT INTO acquisti (
        durata, prezzi, expectedtime
    ) VALUES (
        '$str', '{$resArray['AMT']}', '$expected'
    )
";

But you should really need to start using prepared statements.


If you wish to pass datetime, then you should format accordinaly, like Y-m-d H:i:s.

PHP example:

$expected = date_create('now')->modify('+7 day')->format('Y-m-d H:i:s');

MySQL example:

$sql = "
    INSERT INTO acquisti (
        durata, prezzi, expectedtime
    ) VALUES (
        '$str', '{$resArray['AMT']}', DATE_ADD(NOW(), INTERVAL 7 DAY)
    )
";
Community
  • 1
  • 1
Glavić
  • 42,781
  • 13
  • 77
  • 107
  • Stupid that i am! I'm always confused because dreamweaver says it's ok but it's not. Yeah usually i use prepared statements but 'cause i don't know how to print the query using PDO if i have to check what i put in the query i use basic query...thanks a lot!! – Fabio Rossi Nov 11 '13 at 11:14
  • @FabioRossi: you cannot see built PDO SQL statement, because it is not built in the PHP; see [this question](http://stackoverflow.com/q/2303972/67332). – Glavić Nov 11 '13 at 11:19
  • @FabioRossi: I have updated my answer. You have "nicer" solutions to add some interval to current time, I added PHP and MySQL example. – Glavić Nov 11 '13 at 17:45
  • Glavic, i don't know what does it mean – Fabio Rossi Nov 18 '13 at 10:35