php 如何使用php和我的sql删除一行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10378355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to delete a row using php and my sql
提问by Rio Salonoy
I'm using PHP to display what is in my MySQL database in a table. I think it is working but the output is still "ERROR". I need to delete all records in a row.
我正在使用 PHP 在表中显示我的 MySQL 数据库中的内容。我认为它正在工作,但输出仍然是“错误”。我需要连续删除所有记录。
<?php
$host="localhost"; // Host name
$username="user1"; // Mysql username
$password="test123"; // Mysql password
$db_name="inventory"; // Database name
$tbl_name="avaya_pabx"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$serial_no=$_GET['serial_no'];
$sql="DELETE FROM $tbl_name WHERE serial_no='$serial_no";
$result=mysql_query($sql);
if ($result)
{
echo "Deleted Successfully";
echo "<br>";
echo "<a href='avayatable.php'> Back to main page </a>";
}
else
{
echo "ERROR!";
// close connection
mysql_close();
}
?>
回答by Robert Martin
I think this is your problem
我认为这是你的问题
$sql="DELETE FROM $tbl_name WHERE serial_no='$serial_no";
There's no closing single-quote. You need
没有结束单引号。你需要
$sql="DELETE FROM $tbl_name WHERE serial_no='$serial_no'";
And if you want to display the error (helps a LOT with debugging), use mysql_error().
如果您想显示错误(对调试有很大帮助),请使用mysql_error().
回答by SuperNoob
You have no closing single quote
你没有结束单引号
Copy this line of code:
复制这行代码:
$sql="DELETE FROM $tbl_name WHERE serial_no='$serial_no'";

