-1

我想不通这个。我环顾四周,在这里和其他地方,他们似乎都在以一种非常全面的方式处理这项工作。我创建了一个用于删除成员的页面。用户输入用户名,单击选择,然后从数据库中检索特定记录。然后用户可以单击删除按钮并删除用户。我遇到的问题是删除部分不起作用。这是html:

<?php
require_once('../include/officer_session_timeout_db.inc.php');
if (isset($_POST['viewmember'])) {
 $username = trim($_POST['username']);
require_once('../include/viewmember.inc.php');
}
?>

上面的部分工作正常。只是删除部分不起作用。

<?php 
if (isset($_POST['delete'])) {
    require_once('../include/deletemember.inc.php');
}
?> 



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org    /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
</head>

<body>



<div id="MainContentBox">




   <Div id="MainContentTitle">DELETE A MEMBER!!!!<br>


          <div id="MainContentText">



          <form id="viewmember" method="post" action="">

User Name: <input type="text" name="username" id="username">  
 <input name="viewmember" type="submit" id="viewmember" value="Search">

</form>

<?php echo $firstname;?> <?php echo $lastname;?>        

          <fieldset style="width:500px">
<legend>Address</legend>
<?php echo $address;?><br>
<?php echo $city;?><br>
<?php echo $state;?> , <?php echo $zip;?>

</fieldset>
<fieldset style="width:500px">
<legend>Contact Information</legend>
E-Mail:<a href="mailto:<?php echo $email;?>"><?php echo $email;?></a> <br>
Home Phone: <?php echo $homephone;?><br>
Cell Phone: <?php echo $cellphone;?><br>
</fieldset>

 <?php
if (isset($success)) {
echo "<p>$success</p>";
} elseif (isset($errors) && !empty($errors)) {
echo '<ul>';
foreach ($errors as $error) {
echo "<li>$error</li>";
}
echo '</ul>';
}
?>

<form id="delete" method="post" action="">

<input name="delete" type="submit" id="delete" value="DELETE MEMBER!!!!">
</form>
         </div>
          </div>

     </body> 

这是 deletemember.inc.php 文件的代码:

<?php
require_once('connection.inc.php');
  $conn = dbConnect('write');
    // prepare SQL statement
$sql = "DELETE FROM members WHERE username='$username'";
  $stmt = $conn->stmt_init();
  $stmt = $conn->prepare($sql);
  // bind parameters and insert the details into the database
  $stmt->bind_param('s', $username);
  $stmt->execute();
 if ($stmt->affected_rows == 1) {
    $success = "Your information has been updated.";
    } else {
    $errors[] = 'Sorry, there was a problem with the database.';
  }
4

2 回答 2

1

用一个 '?' 标记要绑定的参数。尝试这个:

$sql = "DELETE FROM members WHERE username=?";
$stmt = $conn->stmt_init();
$stmt = $conn->prepare($sql);
// bind parameters and insert the details into the database
$stmt->bind_param('s', $username);

mysqli 需要知道要在查询中的哪个位置绑定参数,因此您使用 . 标记每个替换?。查看 bind_param 文档以获取更多信息和示例: http: //php.net/manual/en/mysqli-stmt.bind-param.php

于 2013-09-22T01:58:07.517 回答
1

我看不到参数's'在哪里。

参数 's' 不存在,因此,您不需要绑定它们。

于 2013-09-22T02:16:56.533 回答