-1

I am having trouble adding 2 days to a date that is in the database. I have tried multiple ways around it but none of them are updating the database.

 include('CONNECT-DB.php');

 // check if the 'id' variable is set in URL, and check that it is valid
 if (isset($_GET['id']) && is_numeric($_GET['id']))
  {
 // get id value
 $id = $_GET['id'];

 // delete the entry
  $id = $_GET['id'];
$result1 = mysql_query("SELECT `offerends` FROM `data` WHERE id=$id");

$date1 = str_replace('-', '/', $result1);
$date2 = date('y-m-d',strtotime($date1 . "+2 days"));

mysql_query("UPDATE `offerends` SET `$date2` WHERE id=$id");

I HAVE REVISITED IT, thanks for the suggestions this is the correct code that now works for my use.

 if (isset($_GET['id']) && is_numeric($_GET['id']))
 {

 $id = $_GET['id'];

  $id = $_GET['id'];
$result1 = mysql_query("SELECT `offerends` FROM cheapest` WHERE id=$id");

$date2 = "DATE_ADD(offerends,INTERVAL 3 DAY)";

mysql_query("UPDATE `cheapest` SET offerends=$date2  WHERE id=$id");
4

4 回答 4

2

你需要做的就是

mysql_query("UPDATE `data` SET `offerends` = `offerends` + INTERVAL 2 DAY WHERE id=$id");

特别是,不要删除条目。您无法更新不存在的内容。;)

另一个重要说明:我不是程序员,但我敢打赌这段代码对SQL Injections是不安全的。不要直接使用数据,正确转义。阅读有关该主题的信息!

于 2013-07-22T12:48:07.543 回答
0

I'm pretty sure your SQL should look like

UPDATE `data` SET `offerends`='$date2' WHERE id=$id

http://dev.mysql.com/doc/refman/5.0/en/update.html

Adjust for language specific details (like whatever those backticks are)

update: changed the link to the mysql docs. It was w3schools before. Honestly though it doesn't matter, the only reason I linked it was to show the sql syntax of

UPDATE [tablename] SET [columnNname] = [value] WHERE [columnname] = [value]
于 2013-07-22T11:13:30.933 回答
0

mysql_query("UPDATE offerendsSET $date2= DATE_ADD(offerends,INTERVAL 2 DAY) WHERE id='$id'");

于 2013-07-22T11:44:12.707 回答
-1
mysql_query("UPDATE `offerends` SET `$date2`= DATE_ADD(offerends,INTERVAL 2 DAY) WHERE id=$id");
于 2013-07-22T11:12:46.377 回答