开发者

mysql update, computer says it works but no change in database

<?php 

  require('dbconnect.php');

  $indexno = $_POST['indexno'];
  $cevap = $_POST['cevap'];
  $cevapdate = gmdate("Y-m-d\TH:i:s\Z");
  $query = "UPDATE soru 
               SET cevap = '$cevap', 
                   cevapdate = '$cevapdate' 
             WHERE `index` = '$indexno'";

$link = mysql_query($query);
if(!$link) {
  die('not worked: ' . mysql_error());
} else {
  mysql_close($con);    
  echo 'worked';
}

?>

Outcome of this php code is "Worked." but th开发者_如何学JAVAere is no change in the database. The thing is Im trying to update the cevap and cevapdate fields on a row by index id.


You need to remove the single quotes from aroud the index. You should not put single quotes around a column name while writing a query. Write your query this way -

$query = "UPDATE soru SET cevap = '$cevap', cevapdate = '$cevapdate' WHERE index = '$indexno'";


You have to escape your rows/table with backticks, not single-quotes.

$query = "UPDATE `soru`
  SET `cevap` = '$cevap', `cevapdate` = '$cevapdate'
  WHERE `index` = '$indexno'";

Also, you should escape your user input to prevent SQL injections.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜