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

Php 从mysql数据库中删除行时出错,php,html,mysql,Php,Html,Mysql,我已经编写了从MYSQL数据库中删除一行的语法。这很好,但我现在移动到另一个页面(复制和粘贴),由于某些原因,它将无法在新页面上工作 我不知道如何添加错误报告,所以只需获取服务器错误 这是密码 <?php $prodID = $_GET["q"]; if ($prodID <= "0") { echo(" <h3>This Product Does Not Exist</h2> <table border='0

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

我不知道如何添加错误报告,所以只需获取服务器错误

这是密码

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

您正在使用字符串检查数学运算符

用这个代替。这就是为什么删除查询中的值为0,这是错误的

if ($prodID <= 0)
而不是

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


尝试在mysql之前删除
@
\u选择\u db

您在
$result
之后和
之前缺少一个结束
"DELETE FROM products WHERE prodID='".$prodID."'"
    <?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());
}
?>

这个问题不属于Java。另外,Java不是JavaScript.Add:
ini\u集('display\u errors',true)
错误报告(E_ALL)到页面顶部以获取错误。如果没有错误,这对人们来说是非常重要的,需要为您调试。请不要在新代码中使用
mysql\u query
。此接口已弃用,如果像此处一样使用不当,则会很危险,并将在PHP的未来版本中删除。您在这段代码中没有并且有严重的错误。如果你严格遵守使用参数化查询的规则,本可以避免这种情况。不要使用
mysql\u*
,因为它已被弃用,请改用
mysqli\ucode>或
PDO
。@Shane-这就是你的确切代码吗?因为您的
else
@DamienOvereem上缺少右括号,所以我添加了您的代码,仍然没有收到任何错误??删除
mysql\u select\u db()
的@infort,可能选择了一个不存在的数据库。
    <?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());
}
?>