DELETE FROM LOOP问题

时间:2016-12-08 20:27:02

标签: php sql

当我运行我的代码时,我收到此错误:

Error1

我已经在我的服务器上测试了SQL并且它正确,这让我相信它是循环不正确。

我知道接下来要解决的安全问题。

if(isset($_GET['rowID']))
    {
        $sql = 'DELETE FROM table WHERE  id="' . $_GET['rowID'] . '";';
        echo "<b>ECHO SQL<b><br>";
        echo $sql;


        if (mysqli_query($connection, $sql)) 
        {
            echo "Record deleted successfully";

        }
        else 
        {
            echo "<br> Error deleting record: " . mysqli_error($connection);
        }


    }

1 个答案:

答案 0 :(得分:0)

在第3行使用正确的GET变量rowID代替row

if(isset($_GET['rowID']))
{
    $sql = 'DELETE FROM table WHERE  id="' . $_GET['rowID'] . '";';
    echo "<b>ECHO SQL<b><br>";
    echo $sql;


    if (mysqli_query($connection, $sql)) 
    {
        echo "Record deleted successfully";

    }
    else 
    {
        echo "<br> Error deleting record: " . mysqli_error($connection);
    }


}