I'm using an HTML form within PHP to try and simultaneously update multiple rows in my MySQL table. The PHP seems to run (kind of) but updates my table with 'Array' in all the affected columns. Can someone please fill in the gaps to my code or explain what I've missed?!
P.S. I know I need to escape my PHP to prevent injection attacks ... that'll come later :)
HTML and PHP code below.
HTML form within PHP echo statement
<form action='edit.php' method='POST' id='scheduler'>
<input type='hidden' id='identifier' name='identifier[]' value='". $row['id'] . "'>
<input type='hidden' id='assoc_to_username' name='assoc_to_username' value='" . $schedule['assoc_to_username'] . "'>
<input id='assoc_to_date' name='assoc_to_date[]' type='text' value='" . $schedule['assoc_to_date'] . "'/>
<select name='assoc_to_start_time[]' id='assoc_to_start_time'>
<option selected disabled='disabled' value='" . $schedule['assoc_to_start_time'] . "'>" . $schedule['assoc_to_start_time'] . "</option>
<option disabled='disabled'>----------</option>
<option value='All day'>All day</option>
</select>
<select name='assoc_to_end_time[]' id='assoc_to_end_time'>
<option selected disabled='disabled' value='" . $schedule['assoc_to_end_time'] . "'>" . $schedule['assoc_to_end_time'] . "</option>
<option disabled='disabled'>----------</option>
<option value=''>No end time</option>
<option value=''>All day</option>
</select>
<input id='taskname' name='taskname[]' type='text' value='" . $schedule['taskname'] . "'/>
<input id='submit' name='submit' class='submit' type='submit' value='Edit' type='submit' />
</form>
PHP process code
require_once('../inc/database-config.php');
$id1 = $_POST['identifier'];
$assoc_to_username = $_POST['assoc_to_username'];
$assoc_to_date = $_POST['assoc_to_date'];
$assoc_to_start_time = $_POST['assoc_to_start_time'];
$assoc_to_end_time = $_POST['assoc_to_end_time'];
$taskname = $_POST['taskname'];
foreach ($_POST['identifier'] as $id1)
{
$sql=mysql_query("UPDATE schedule SET assoc_to_date= $assoc_to_date, assoc_to_start_time= $assoc_to_start_time, assoc_to_end_time= $assoc_to_end_time, taskname=$taskname WHERE assoc_to_username=$assoc_to_username");
header("Location: ../admin.php?action=edited");
;}
if (!mysql_query($sql,$dbcon))
{ die (header("Location: ../error.php")); }
mysql_close($dbcon);
Please help!
[]from the name attributes of each of your inputs.