0

我已经编写了从 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

4 回答 4

1

}你在你之后$result和你之前错过了一个结束?>

于 2013-08-06T16:18:10.860 回答
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 之前删除

于 2013-08-06T14:36:28.667 回答
0
"DELETE FROM products WHERE prodID='".$prodID."'"
于 2013-08-06T16:12:10.537 回答
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());
}
?>
于 2013-08-06T16:39:54.827 回答