Jump to content

[SOLVED] A syntax error in a foreach statement


swatisonee

Recommended Posts

Hello,

I have the foll. code. The print_r(($array)); lines throws up the data correctly, but the foreach statement thereafter gives me an error ,line 32 being the foreach statement.

Would someone be able to guide me on the correct syntax ? Thanks ! Swati


[quote]
Parse error: syntax error, unexpected T_IS_GREATER_OR_EQUAL, expecting ')' in /home/easte9/public_html/egor/group5.php on line 32
[/quote]

[code]

$group = $_POST["group"];

$customer = $_POST["customer"];// this comes from  multiple checkboxes on a previous page

$array = implode(",", $customer);

print_r(($array)); // prints values correctly

foreach ($array as $key>= $value)      // this line is where the error is
{

$sql = "UPDATE  `Customers` SET `CGID` = $group WHERE `CID` = '$value'";
// echo $sql;
//each record having value of $array, like say 1,10,25 (that is $value)  etc needs to get updated with the $group figure

$result = mysql_query($sql);

  echo "Information Updated" ;
}
[/code]
You convert the $_POST array [b]customer[/b] to a [b]string[/b] using [b]$array = implode()[/b], so the foreach() will not work even after fixing [b]>=[/b]!

this...


[code]foreach ($array as $key>= $value)      // this line is where the error is
{[/code]


should be...

[code]foreach ( $_POST['customer'] as $key => $value )      // this line is where the error is
{[/code]


printf

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.