Search the Community
Showing results for tags 'multiple arrays'.
-
Hi, this is the first time I have used arrays in php. I have searched around many other posts but can't seem to get my head around it. I am trying to process multiple arrays entered on a form. The number of entries could be different each time. This is the code I have so far: <?php function submitResults($fixture_id, $ht_goals, $at_goals, $et, $h_pens, $a_pens, $postponed) { //Put group selections into arry in MySQL INSERT value format $valuesAry = array(); foreach(array_keys($fixture_id) as $n) { $valuesAry[] = "($fixture_id[$n], $ht_goals[$n], $at_goals[$n], $et[$n], $h_pens[$n], $postponed[$n])"; } $query = "INSERT INTO test_results (fixture_id, ht_goals, at_goals, et, pens, postponed) VALUES ".implode(', ', $valuesAry); $result = mysql_query($query) or die("Query: {$query}<br>Error: ".mysql_error()); return $result; } ?> It currently displays an error: 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 ' , , , ), (109, , , , , ), (162, , , , , ), (316, , , , , ), (563, , , , , ), (6' at line 2 Any help anyone can give me would be greatly appreciated.
- 11 replies
-
- array
- multiple arrays
-
(and 1 more)
Tagged with:
-
Hi, I have multiple txt files and I would like to loop them all the the same time Since foreach works with only one array, how do i loop and echo 3 arrays ($handle, $handle2 and $handle_date)? Thanks if(isset($_POST['name'])AND(isset($_POST['msg']))){ $name = $_POST['name']; $msg = $_POST['msg']; if(!empty($name)AND(!empty($msg))) { $handle = fopen('1all_names.txt', 'a'); fwrite($handle, $name."\n"); fclose($handle); $handle2 = fopen('1msg.txt', 'a'); fwrite($handle2, $msg."\n"); fclose($handle2); $handle_date = fopen('1date.txt', 'a'); fwrite($handle_date, $date."\n"); fclose($handle_date);