PHP - MySQL - 删除行

时间:2012-06-14 11:50:07

标签: mysql

我不太确定我做错了什么。我试图用这段代码删除整行,但它无法正常工作。没有错误发生它打印它被删除的行但是当我去看看它不起作用。有什么想法吗?

<?
$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)
?>

4 个答案:

答案 0 :(得分:9)

您使用$order代替了查询变量$sql

$sql="DELETE FROM times WHERE id='$id'";
mysql_query($sql);

答案 1 :(得分:7)

我使用此代码工作了!

<?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());      

?>

答案 2 :(得分:2)

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);
        }
    }       
}
?>  

答案 3 :(得分:1)

delete.php

<?php
    include "connect.php";
    $id =$_REQUEST['id'];

    // sending query
    mysql_query("DELETE FROM utilizatori WHERE id = '$id'")
    or die(mysql_error());      

    ?>

是正确的,我测试并从ID中删除

这里是按钮删除:`

<?<a href=\"delete.php?id=$row[id]\">Delete</a>`?>