PHP - MySQL - 删除行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11032456/
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
PHP - MySQL - Delete Row
提问by Matt Rogers
I am not too sure what i am doing wrong. i am trying to delete the entire row with this code but it is not working. No error is happening it prints the line that it was deleted but when i go and have a look it is not working. Any thoughts?
我不太确定我做错了什么。我正在尝试使用此代码删除整行,但它不起作用。没有发生错误,它打印了它被删除的行,但是当我去看看它不起作用时。有什么想法吗?
<?
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("theobse1_scores", $con);
$sql="DELETE FROM times WHERE id='$id'";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record deleted go back to delete another!";
mysql_close($con)
?>
采纳答案by Matt Rogers
I got it working using this code!
我使用这段代码让它工作了!
<?php
$id =$_REQUEST['id'];
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database", $con);
// sending query
mysql_query("DELETE FROM times WHERE id = '$id'")
or die(mysql_error());
?>
回答by Chibuzo
You used $order
instead of your query variable $sql
您使用$order
而不是查询变量$sql
$sql="DELETE FROM times WHERE id='$id'";
mysql_query($sql);
回答by goharkhan
else
{
$qry = "SELECT * FROM my_login WHERE email = '".$email."' LIMIT 1";
$res = mysql_query($qry);
if(mysql_num_rows($res) > 0)
{
echo "Email already exists!";
}
else
{
$qry="INSERT INTO my_login SET name='$name',city='$city',comment='$comt',password='$pass',email='$email'";
mysql_query($qry);
}
}
}
?>
回答by razvan
delete.php
<?php
include "connect.php";
$id =$_REQUEST['id'];
// sending query
mysql_query("DELETE FROM utilizatori WHERE id = '$id'")
or die(mysql_error());
?>
is corect, I tested and delete from ID
是正确的,我测试并从 ID 中删除
and here is the button delete: `
这是删除按钮:`
<?<a href=\"delete.php?id=$row[id]\">Delete</a>`?>