数组语法错误PHP

时间:2014-01-11 07:33:29

标签: php mysql arrays

我收到错误*您的SQL语法出错了;检查与MySQL服务器版本对应的手册,以便在尝试更新和发送电子邮件时,在第1行*的“[0]”附近使用正确的语法。

$updatelist = explode(",",$Limited);
print_r($updatelist); // echos Array ( [0] => samplemail@gmail.com [1] => samplemal@yahoo.com [2] => ) 

$totalupdates = count($updatelist)-1;
for ($y = 0; $y < $totalupdates; $y++)
{
  $updatemail = "UPDATE tblusers SET date= '$date' WHERE Email = 'updatelist[$y]'";
  $updatefree = mysql_query($updatemail);

  echo $updatemail;

}

$ updatelist [$ y]有什么问题?它应该通过$ updatelist [0]循环到$ updatelist [1]吗?

4 个答案:

答案 0 :(得分:3)

更改$updatelist[$y]而不是updatelist[$y]

答案 1 :(得分:1)

我认为问题在于:

$updatemail = "UPDATE tblusers SET date= '$date' WHERE Email = 'updatelist[$y]'";

试试这个:

$updatemail = "UPDATE tblusers SET date = '$date' WHERE Email = '$updatelist[$y]'";

答案 2 :(得分:0)

试试这段代码:

$updatelist = explode(",",$Limited);
print_r($updatelist); // echos Array ( [0] => samplemail@gmail.com [1] => samplemal@yahoo.com [2] => ) 
$totalupdates = count($updatelist)-1;
foreach ($updateList as $key=>$val)
{
     $updatemail = "UPDATE tblusers SET date= '$date' WHERE Email = '".$val."'";
     $updatefree = mysql_query($updatemail);
}
 echo $updatemail;

答案 3 :(得分:-1)

尝试:

  $updatemail = "UPDATE tblusers SET date= '".$date."' WHERE Email = '".$updatelist[$y]."'";