I'm trying to delete MySQL records in PHP using check boxes. I echoed each line and everything seems fine. The values and formats of the variables and arrays are correct.
But when I tried to echo $delete
(which is the DELETE
query) using VAR_DUMP()
, it displays bool(false)
(which means it doesn't get the value of the variable $emailID
passed to it, right?). Why?
if (isset($_POST['deleteUser']) && isset($_POST['marked_user']))
{
$marked_user = $_POST['marked_user'];
foreach($marked_user as $user => $emailID)
{
$emailID = (int)$emailID;
$delete = $base -> query( "DELETE FROM tickets.allowed_users WHERE allowed_users.emailID = '$emailID'");
}
header('Location: viewTickets.php?viewType=U');
}
This is the HTML part from a separate PHP file:
echo "<form action='addUser.php' method='POST'><table class='results3' align='center' cellspacing='0'>
<tr><th class='head' id='headleft' width='10%'></th>
<th class='head' id='headright' colspan='4'>E-mail</th></tr>";
while( $row = mysqli_fetch_array($sql) )
{
$email = $row['email'];
$emailID = $row['emailID'];
echo "<tr><td width='1%' class='results'><input type='checkbox' name='marked_user[]' value='$emailID'></td>
<td class='results' colspan='4'>" . $row['email']."</td></tr>";
}
echo "<td colspan='3'><input type='submit' class='button' name='deleteUser' value='Delete'></td></form>";
And this is my table:
CREATE TABLE allowed_Users
(
emailID INT UNSIGNED NOT NULL AUTO_INCREMENT,
email VARCHAR(50) NOT NULL,
PRIMARY KEY( emailID )
);