Forum Moderators: coopster
Basically, i have a system that writes to a MySQL Database, i have a system to view the records. im having trouble deleting multiple records.
Ok, i made a loop with all the checkboxes named 'guestid[]' to create the array from the form.
I then created an if statement, with a for loop, to display the records i selected (Deleting should be straightforward, i made this so i know what values are being passed into the array)
Ok, the Count, correctly identifies the amount of records selected.... great
the for loop displays the correct number of array instances.. great-ish
The problem is, the array elemnt dont have the information that i want in them (being the guest_id data from the sql database)
The .$row['guest_id'] part in the table works, and displays the correct value
<form method="post" action="<?php echo($self);?>">
<?php
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<tr>\n";
echo "<td>". $row['guest_id']?><input name="guestid[]" type="checkbox" value=<?php $row['guest_id']?>></td>
<?php
echo "<td>" . $row['name'] ;
echo "<td>" . $row['surname'];
}
?>
<tr>
<td>
<input type="submit" name="submit" value="submit"></td>
</form>
</tr>
</table>
<?php
$delid = $_POST["guestid"];
$how_many=count($delid);
echo("".$how_many."<br>");
if ($how_many>0)
{
echo ("You chose the following records:<br>");
}
for ($i=0; $i<$how_many; $i++)
{
echo (($i+1) . " - " . $delid[$i] . "<br>");
}?>
(Its messy, but the this is the way i program... make snippets that work, tidy up, then put into the main code)
Thanks in advance
this portion seems to have some mismatched tags
echo "<tr>\n";
echo "<td>". $row['guest_id']?><input name="guestid[]" type="checkbox" value=<?php $row['guest_id']?>></td>
<?php
echo "<td>" . $row['name'] ;
echo "<td>" . $row['surname'];
try this replacement
echo "<tr>\n";
echo "<td>". $row['guest_id'] . '<input name="guestid[]" type="checkbox" value="' . $row['guest_id'] . '"></td>';
echo "<td>" . $row['name'] ;
echo "<td>" . $row['surname'];
see if that makes the difference.