[英]How can I add a functional delete button and a textbox to this simple .php delete script?
The admin will type the username of the member and hit delete button to remove the member from the database 管理员将键入成员的用户名,然后单击删除按钮以从数据库中删除该成员
/* 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);
?>
<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>
Now In Your PHP: 现在在您的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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.