Can someone explain this code for me
Posted: Sat Sep 12, 2009 4:14 am
This is a code taken from Head First PHP&MySQL
I am confused about the array within the while loop. Specifically, I want to know how it works, because i don't see anything action on the todelete[]
I am confused about the array within the while loop. Specifically, I want to know how it works, because i don't see anything action on the todelete[]
Code: Select all
<?php
$dbc = mysqli_connect('localhost','root','','storeproj');
$result = mysqli_query($dbc, "SELECT * FROM email_list");
if(!isset($_POST['submit']))
{
while($row = mysqli_fetch_array($result))
{
echo '<input type = "checkbox" value ="' . $row['id'] . '" name = "todelete[]"/>';
echo $row['first_name'] . " ";
echo $row['last_name'] . " ";
echo $row['email'];
echo '</br>';
}
echo '<input type ="submit" value="submit" name="submit">';
}
else
{
foreach($_POST['todelete'] as $person)
{
mysqli_query($dbc , "DELETE FROM email_list WHERE id = $person");
}
}