I have a problem with my code in php.
I would like to delete multiple lines from a table with select box when a users
press deleting button.
But I don’t have in my database an id field. So it’s difficult for me to do it
Could you help me please ?
$user_query= "SELECT * FROM user";
$user_result = mysql_query($user_query);
$count=mysql_num_rows($user_result);
echo "<form name='form1' method='post' action=''>";
echo "<table>";
echo "<tr>";
echo "<th scope='col'>#</th>";
echo "<th scope='col'>username</th>";
echo "<th scope='col'>Email</th>";
echo "<th scope='col'>tel</th>";
echo "<th scope='col'>name</th>";
echo "<th scope='col'>surname</th>";
echo "<th scope='col'>type</th>";
echo "</tr>";
while($row = mysql_fetch_array($user_result))
{
echo "<tr>";
echo '<td><input name="checkbox[]" type="checkbox" username="checkbox[]" value="'.$row['username'].'"></td>';
echo '<td><b>'.$row['username'].'</b></td>';
echo '<td><a href="mailto:'.$row['e_mail'].'" title="send Email">'.$row['e_mail'].'</a></td>';
echo '<td>'.$row['phone_number'].'</td>';
echo '<td>'.$row['name'].'</td>';
echo '<td>'.$row['surname'].'</td>';
echo '<td><img src="images/admin.png" width="40" height="45" title="admin"/></td>';
echo '</tr>';
}
echo '<tr><td colspan="7"><input name="delete" type="submit" id="delete" value="Deleting"></td></tr>';
echo "</table>";
echo "</form>";
if (isset($_POST['delete']))
{
// how can I take checkboxes value and delete values ??
// $sql = "DELETE FROM user WHERE username=...;
$result = mysql_query($sql);
// if successful redirect
if($result)
{
header("location: ShowUsers.php");
}
}
As commented, If you have your username is unique identifier, Then replace with changes accordingly:=