从mysql数据库中删除行时出错

时间:2013-08-06 14:31:29

标签: php html mysql

我编写了从MYSQL数据库中删除行的语法。这工作正常,但我现在将其移动到另一页(复制和粘贴),由于某种原因,它将无法在新页面上工作

我不确定如何添加错误报告,因此只需获取server error

这是代码

<?php

$prodID = $_GET["q"];

if ($prodID <= "0") {
    echo("
        <h3>This Product Does Not Exist</h2>
        <table border='0'>
        <tr>
            <td>
                <a href=catalogue.html'><button class='btn btn-info'><font color='white'>&nbsp;Add A     New product&nbsp;</font></a></button>
            </td>
            <td>                        
                <a href='manageproducts.php'><button class='btn btn-info'><font color='white'>Back to Products</font>  </a>
            </td>
        </tr>
            </table>
    ");
} else {
    $con = mysql_connect("localhost", "cl49-xxx", "xxx");

    if (!$con) {
        die('Could not connect: ' . mysql_error());
    }

    @mysql_select_db("cl49-XXX", $con) or die("Unable to select database");
    $result = mysql_query("DELETE FROM products WHERE prodID=$prodID") or die(mysql_error());
?>

4 个答案:

答案 0 :(得分:1)

您在}之后和$result

之前错过了结束?>

答案 1 :(得分:0)

你正在用字符串检查数学运算符。

请改用它。这就是为什么你的删除查询中有0值是错误的

if ($prodID <= 0)

编辑:

使用它。

mysql_query("DELETE FROM products WHERE prodID=$prodID") ;

而不是

$result = mysql_query("DELETE FROM products WHERE prodID=$prodID") 

编辑:

尝试在mysql_select_db

之前删除@

答案 2 :(得分:0)

"DELETE FROM products WHERE prodID='".$prodID."'"

答案 3 :(得分:0)

    <?php

    $prodID = $_GET["q"];

    if ($prodID <= "0") {
        echo("
            <h3>This Product Does Not Exist</h2>
            <table border='0'>
            <tr>
                <td>
                    <a href=catalogue.html'><button class='btn btn-info'><font color='white'>&nbsp;Add A     New product&nbsp;</font></a></button>
                </td>
                <td>                        
                    <a href='manageproducts.php'><button class='btn btn-info'><font color='white'>Back to Products</font>  </a>
                </td>
            </tr>
                </table>
        ");
    } else {
        $con = mysql_connect("localhost", "cl49-xxx", "xxx");

        if (!$con) {
            die('Could not connect: ' . mysql_error());
        }


        @mysql_select_db("cl49-XXX", $con) or die("Unable to select database");
        $result = mysql_query("DELETE FROM products WHERE prodID=$prodID") or die(mysql_error());
}
?>