1

我想在使用 php 从 mysql 中删除特定行之前发出警告,这是我的代码,请建议我该怎么做?删除脚本运行良好。

这是我的users-delete.php

<?php include("../includes/config.php"); ?>
<?php

 if ($_SESSION["isadmin"])
{

$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con) { die('Could not connect: ' . mysql_error()); }

mysql_select_db($dbname, $con);
$accountid=$_GET["id"];
$result = mysql_query("SELECT * FROM accounts WHERE (id='".$accountid."')");
while($row = mysql_fetch_array($result))
{
   $id=$row['id'];
   $firstname = $row['firstname'];
   $lastname = $row['lastname'];
   $password = $row['password'];
   $email=$row['email'];
   $type=$row['type'];
}
mysql_close($con);
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Delete User</title>
<link rel="StyleSheet" href="../admin/css/style.css" type="text/css" media="screen">
</head>
<body>
<?php include("../admin/includes/header.php"); ?>
<?php include("../admin/includes/nav.php"); ?>
<?php include("../admin/includes/manage-users-aside.php"); ?>
<div id="maincontent">

<div id="breadcrumbs">
    <a href="">Home</a> >
     <a href="">Manage Users</a> >
     <a href="">List Users</a> >
     Delete User
</div>
<h2>Delete User</h2>

<form method="post" action="users-delete-action.php">
<input type="hidden" value="<?php echo $accountid; ?>" name="id" />
<label>Email/Username:</label><input type="text" name="email" value="<?php echo $email;     ?>" /><br /><br />
<label>Password:</label><input type="password" name="password" value="<?php echo   $password;?>" /><br /><br />
<label>First Name:</label><input type="text" name="firstname" value="<?php echo   $firstname; ?>" /><br /><br />
<label>Last Name:</label><input type="text" name="lastname" value="<?php echo  $lastname; ?>" /><br /><br />
<label>Type:</label><br />
<input type="radio" name="type" value="S" <?php if ($type == 'S') echo   'checked="checked"'; ?> />Student<br />
<input type="radio" name="type" value="T" <?php if ($type == 'T') echo  'checked="checked"'; ?> /> Teacher<br />

    <input type="submit" value="Delete" />
</form>



</div>

</body>
<?php include("../admin/includes/footer.php"); ?>
</html>
<?php
}
else
{
    header("Location: ".$fullpath."login/unauthorized.php");

}
?>

这是用户删除action.php

<?php include("../includes/config.php");?>
<?php

$id=$_POST["id"];
$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("ombts", $con);
$query=("DELETE FROM accounts WHERE id='".$id."'");
$result=mysql_query($query);
 if($result){
echo "User has been Deleted Successfully!!";
}mysql_close($con);
?>

请帮助,我将不胜感激:)

4

3 回答 3

2

提交时附上确认

<form method="post" action="users-delete-action.php" 
 onsubmit="return confirm("Are you sure you wish to delete?");">
于 2012-08-29T07:57:17.983 回答
1

在提交按钮上使用它:

<input type="submit" value="Delete" onclick="return confirmSubmit()" />
于 2012-08-29T07:54:59.200 回答
0

1解决方案只是修改表格:

    <form name="form" method="post" action="users-delete-action.php">
<input type="hidden" value="<?php echo $accountid; ?>" name="id" />
<label>Email/Username:</label><input type="text" name="email" value="<?php echo $email;     ?>" /><br /><br />
<label>Password:</label><input type="password" name="password" value="<?php echo   $password;?>" /><br /><br />
<label>First Name:</label><input type="text" name="firstname" value="<?php echo   $firstname; ?>" /><br /><br />
<label>Last Name:</label><input type="text" name="lastname" value="<?php echo  $lastname; ?>" /><br /><br />
<label>Type:</label><br />
<input type="radio" name="type" value="S" <?php if ($type == 'S') echo   'checked="checked"'; ?> />Student<br />
<input type="radio" name="type" value="T" <?php if ($type == 'T') echo  'checked="checked"'; ?> /> Teacher<br />

    <input type="button" value="Delete" onClick="if (confirm('Are you sure you want to delete ?')) document.form.submit(); return false;">" /> </form>​

注意力 :

您用来删除的方法非常不安全。如果有人起诉萤火虫编辑隐藏的输入,他可以删除任何人!

编辑:小提琴链接 - http://jsfiddle.net/M7fG2/

于 2012-08-29T07:58:18.327 回答