bravo14 Posted September 16, 2014 Share Posted September 16, 2014 Hi Guys I have a number of arrays that are posted from a form They are $home_rider $order $away_rider $awayorder for each home rider I want to to action the following query "INSERT INTO tbl_lg_rider_order (`name`,`card_id`,`homeaway`,`riderorder`) VALUES ('$homerider',$card_id,'h','$homeorder')" and for each away rider I want to do the following "INSERT INTO tbl_lg_rider_order (`name`,`card_id`,`homeaway`,`riderorder`) VALUES ('$awayrider',$card_id,'a','$awayorder')" I am using the following code $i=0; for($i){ $homerider=$home_rider[$i]; $homeorder=$order[$i]; $homesql="INSERT INTO tbl_lg_rider_order (`name`,`card_id`,`homeaway`,`riderorder`) VALUES ('$homerider',$card_id,'h','$homeorder')"; echo $homesql; $i++; } $i=0; for($i){ $awayrider=$away_rider[$i]; $awayorder=$awayorder[$i]; $homesql="INSERT INTO tbl_lg_rider_order (`name`,`card_id`,`homeaway`,`riderorder`) VALUES ('$awayrider',$card_id,'a','$awayorder')"; echo $awaysql; $i++; } I am getting an error saying Parse error: syntax error, unexpected ')', expecting ';' Where am I going wrong? Quote Link to comment Share on other sites More sharing options...
Barand Posted September 16, 2014 Share Posted September 16, 2014 your for() syntax is wrong http://uk1.php.net/manual/en/control-structures.for.php Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 16, 2014 Share Posted September 16, 2014 You might also want to finish your code and add a query call and a test of its results inside that loop. Depending on where your input is coming from (the user?) you should also be concerned about security and use prepared queries. Hopefully you are NOT planning on using MySQL_* functions. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 16, 2014 Share Posted September 16, 2014 Better to use a foreach() loop $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); $sql = "INSERT INTO tbl_lg_rider_order (`name`,`card_id`,`homeaway`,`riderorder`) VALUES (?,?,?,?)"; $stmt = $db->prepare($sql); $stmt->bind_param('siss', $name,$card_id,$ha,$rideorder); foreach ($home_rider as $k => $name) { $ha = 'h'; $rideorder = $order[$k]; $stmt->execute(); } foreach ($away_rider as $k => $name) { $ha = 'a'; $rideorder = $awayorder[$k]; $stmt->execute(); } 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.