When you have a form that has multiple textboxes, mon-sun(column) for many people(row), it can be very difficult to add these to a database easily!
This should make the most sense!!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
<?php require('dbconnect.php'); $jobid = $mysqli->real_escape_string($_POST['jobid']); if(!empty($_POST['mon'])) { foreach($_POST['mon'] as $check) { $mon[] = $check; } } if(!empty($_POST['tue'])) { foreach($_POST['tue'] as $check) { $tue[] = $check; } } $cmon = count($mon); // how many times? for($x = 0; $x < $cmon; $x++) { $str[] = "('$jobid','{$mon[$x]}','{$tue[$x]}')"; } $s = implode(',',$str); echo $sql = "INSERT INTO hours (jobid,mon,tue) VALUES $s"; if ($mysqli->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $sql->error; } ?> |