swatisonee Posted January 3, 2007 Share Posted January 3, 2007 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 correctlyforeach ($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] Link to comment https://forums.phpfreaks.com/topic/32748-solved-a-syntax-error-in-a-foreach-statement/ Share on other sites More sharing options...
effigy Posted January 3, 2007 Share Posted January 3, 2007 [tt]$key>= $value[/tt] should be [tt]$key => $value[/tt]. Link to comment https://forums.phpfreaks.com/topic/32748-solved-a-syntax-error-in-a-foreach-statement/#findComment-152434 Share on other sites More sharing options...
swatisonee Posted January 3, 2007 Author Share Posted January 3, 2007 I tried that but too it just prints the values but the sql statement does not get processed. Link to comment https://forums.phpfreaks.com/topic/32748-solved-a-syntax-error-in-a-foreach-statement/#findComment-152436 Share on other sites More sharing options...
printf Posted January 3, 2007 Share Posted January 3, 2007 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 Link to comment https://forums.phpfreaks.com/topic/32748-solved-a-syntax-error-in-a-foreach-statement/#findComment-152444 Share on other sites More sharing options...
swatisonee Posted January 3, 2007 Author Share Posted January 3, 2007 Hi Printf, that worked great and thank you but i did not understand the logic. since $array is giving me the individual values of 1,10 , 15, shouldnt the foreach take those values forward ?Thanks.Swati Link to comment https://forums.phpfreaks.com/topic/32748-solved-a-syntax-error-in-a-foreach-statement/#findComment-152464 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.