0

I get the error *You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[0]' at line 1 * when trying to update and email.

$updatelist = explode(",",$Limited);
print_r($updatelist); // echos Array ( [0] => [email protected] [1] => [email protected] [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;

}

What's wrong with the $updatelist[$y] ? Should it loop through $updatelist[0] to $updatelist[1] ?

4 Answers 4

3

change $updatelist[$y] instead of updatelist[$y]

Sign up to request clarification or add additional context in comments.

Comments

1

I think the problem is here:

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

Try this:

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

2 Comments

Oh thanks! I've been staring at that for a moment now but I haven't realized I missed the "$" sign.
No problem! Those sure can sneak up on you if you're not careful.
0

Try this code:

$updatelist = explode(",",$Limited);
print_r($updatelist); // echos Array ( [0] => [email protected] [1] => [email protected] [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;

1 Comment

try to use foreach loop that will give you single value
-1

Try:

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

1 Comment

I thought at first that was it too, but then realized that single-quotes inside double-quoted strings in PHP aren't special characters. Then I saw the missing $. (:

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.