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");

}
?>

これは users-delete-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>​

注意 :

削除に使用している方法は非常に安全ではありません。誰かが非表示の入力を編集するためにfirebugを訴えた場合、彼は誰でも削除できます!

編集:フィドルリンク - http://jsfiddle.net/M7fG2/

于 2012-08-29T07:58:18.327 に答える