简体   繁体   English

这会更新我的sql信息吗?

[英]Will this update my sql information?

Stupid title I know. 我知道这个愚蠢的头衔。 I have this: 我有这个:

$x = array_keys($_POST);
foreach($x as $y) {

 $query = "UPDATE * FROM  events (PromotionalTimeLine = "$_POST[$y]" WHERE EventID='$y'";
  $result = mysql_query($query);
  print_r($result);

}

I need to update only the PromotionalTimeLine cell for specific rows with $y as their EventID . 我只需要使用$y作为它们的EventID更新特定行的PromotionalTimeLine单元格。 Will this do that? 这样可以吗?

No, You have mysql syntax error with update query. 不,您在更新查询时遇到mysql语法错误。

$query = "UPDATE events 
          SET PromotionalTimeLine = '".mysql_real_escape_string($_POST[$y])."' 
          WHERE EventID='".$y."'";

You string concatenation has some problems. 您的字符串连接有一些问题。 It should be 它应该是

$query = "UPDATE events SET PromotionalTimeLine = '" .$_POST[$y]. "' WHERE EventID='".$y."'";

And also you have not sanitized your input, Which I'd advise you to do so the cose is not vulnerable to SQL injection or similar attacks. 另外,您还没有清除输入内容,我建议您这样做,因为cose不会受到SQL注入或类似攻击的攻击。 Here is an detailed post on sanitizing input - What's the best method for sanitizing user input with PHP? 这是有关清理输入的详细信息- 用PHP清理用户输入的最佳方法是什么?

Incidentally, none of the other answers worked for me. 顺便说一句,没有其他答案对我有用。 This worked though: 虽然有效:

mysql_query("UPDATE events 
          SET PromotionalTimeLine = '$_POST[$y]'
          WHERE EventID='$y' ");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM