如何在这个简单的.php删除脚本中添加功能删除按钮和文本框?

时间:2015-01-29 04:57:03

标签: php html mysql

管理员将键入成员的用户名,然后单击“删除”按钮以从数据库中删除该成员     

/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "", "phplogin");

// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Attempt delete query execution

$sql = "DELETE FROM users WHERE username='mrs.snowballs'";
if(mysqli_query($link, $sql)){
echo "Records were deleted successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

// Close connection
mysqli_close($link);
?>

1 个答案:

答案 0 :(得分:0)

<form action='simple.php' method='post'>
    What Name You want to delete : <input type='text' name='del'/>
    <input type='submit' name='submit' value='delete'/>
</form>

现在在你的PHP中:

if(isset($_POST['submit']))
 {
  $name = $_POST['del'];
   $link = mysqli_connect("localhost", "root", "", "phplogin");

   // Check connection
     if($link === false){
     die("ERROR: Could not connect. " . mysqli_connect_error());

      // Attempt delete query execution

    $sql = "DELETE FROM users WHERE username='$name'";
    if(mysqli_query($link, $sql)){
    echo "Records were deleted successfully.";
    } else{
   echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
    }


    // Close connection
    mysqli_close($link);
 }