これは、ユーザーを削除するための私のコード全体です:
<?php
$page_title = 'Delete a User';
include ('includes/header.html');
echo '<h1>Delete a User</h1>';
if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { // From view_users.php
$id = $_GET['id'];
} elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { // sbmsn
$id = $_POST['id'];
} else { // No valid ID, kill the script.
echo '<p class="error">This page has been accessed in error.</p>';
include ('includes/footer.html');
exit();
}
require_once ('../connect.php');
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if($_POST['sure'] == 'Yes') {
$q="DELETE FROM user WHERE user_id= $id ";
$r= @mysqli_query ($dbc, $q);
if(mysqli_affected_rows($dbc) == 1) {
echo '<p>The user has been deleted</p>';
}
else {
echo '<p class="error">Sorry! the user could not be deleted.</p>';
echo '<p>' . mysqli_error($dbc) . '<br/>Query: '.$q. '</p>';
}
}
else {
echo '<p>The user has not been deleted.</p>';
}
}
else {
$q="SELECT first_name FROM user WHERE user_id=$id";
$r= @mysqli_query($dbc,$q);
if(mysqli_num_rows($r) == 1) {
$row = mysqli_fetch_array($r,MYSQLI_NUM);
echo "<h3>Name: $row[0]</h3> Are you sure you want to delete this user?";
echo '<form action="delete_user.php" method="post">
<p> <input type="radio" name="sure" value="Yes" />Yes</p>
<p> <input type="radio" name="sure" value="No" checked="checked" />No</p>
<input type="submit" name="submit" value="submit" />
<input type="hidden" name="id" value=" '.$id.' "/>
</form>';
}
else {
echo '<p class="error">ERROR Sorry!</p>';
}
}
mysqli_close($dbc);
include ('includes/footer.html');
?>
しかし、エラーが発生するたびに
This page has been accessed in error
スタッフは、$id
ユーザーの情報を編集するために、同じ種類のスクリプトに取り組んでいます。