Checkbox selected items deletion instead of 1 by 1 deletion (PHP)
delete.php
session_start();
if (!session_is_registered(validated)) {
header("Location: index.php");
}
elseif (isset($_GET['user']) && isset($_GET['pass'])) {
$con = mysql_connect('xxx', 'xxx_xxx', 'xxx') or die ("开发者_如何学Python<font color=\"red\">Server is unavailable. Try again later.</font>");
mysql_select_db("xxx", $con);
$user=$_GET['user'];
$pass=$_GET['pass'];
mysql_query("DELETE FROM `accounts` WHERE `username`='$user' AND `password`='$pass'");
mysql_close($con);
}
?>
It works with my main thing but the thing I was wondering about is mass deleting. Using a checkbox selection instead of <a href="delete.php?user=$row[0]&pass=$row[0]">[x]</a>
How would I go about doing this?
have the select boxes share the same name
<?php foreach($rows as $row):?>
<input type="checkbox" name="ids[]" value="<?php echo $row;?>">
<?php endforeach;?>
(in this case $rows is a array of numerical ids use whatever ur row uses as primary key)
this would (when submited to a php script) would give you and array in $_POST called ids;
$IDArray = $_POST['ids'];
You should add a form with a checkbox. PHP can process all the results with a form submission.
精彩评论