php - 如何删除一行而不是所有行

标签 php mysql

如何使用我拥有的代码删除一行。它允许我删除所有行,而不是带有 ID 的一行,不确定我做错了什么,不确定它是否是我的循环或什么。

<?php
include_once('dbconnect.php');
echo "<form action='delete.php' method='post' id = 'deleteForm'>";

$sqlARTICLEQuery = "SELECT * FROM articles where pageId=$paqueryRow[pageId] order by articleId";
    $articlequeryResult = mysqli_query($conn,$sqlARTICLEQuery);
    while ($articlequeryRow = mysqli_fetch_assoc($articlequeryResult))
    { echo "<input type = 'radio' name = '$articlequeryRow[articleId]' method = 'post'>".$articlequeryRow['articleId']."&nbsp".$articlequeryRow['articleTitle']."&nbsp";
        echo "<input name='ARTSubmit' type='submit' value='delete record' /><br/>";
        if (isset($_POST['ARTSubmit'])){
            $artDeleteQuery = "DELETE FROM articles where pageId = $paqueryRow[pageId] AND articleId=$articlequeryRow[articleId].";

            if(mysqli_query($conn, $artDeleteQuery)){
                echo "Record deleted successfully";
            } else {
                echo "Error deleting record: " . mysqli_error ($conn);
            }
        }
$sqlTEXTQuery = "SELECT * FROM text where articleId=$articlequeryRow[articleId] order by textId";
$textqueryResult = mysqli_query($conn,$sqlTEXTQuery);                   
while ($textqueryRow = mysqli_fetch_assoc($textqueryResult))
        {
            echo "<input type = 'radio' name = '$textqueryRow[textId]' method = 'post'>".$textqueryRow['textId']."&nbsp".$textqueryRow['textTitle']."&nbsp"; //how can I print articles.pageId to match with pages.pageId
            echo "<input name='TEXTSubmit' type='submit' value='delete record' /><br/>";
            if (isset($_POST['TEXTSubmit'])){
                $textDeleteQuery = "DELETE FROM text where articleId = $articlequeryRow[articleId] AND textId = $textqueryRow[textId].";

                if(mysqli_query($conn, $textDeleteQuery)){

                    echo "Record deleted successfully";
                } else {
                    echo "Error deleting record: " . mysqli_error ($conn);
                }
            }echo "<br />"
        }echo "<br />"
}echo "</form>"
$conn->close();
?>

最佳答案

您忘记了 echo 中第 2 行的结束引用。我删除了第 20 行查询删除行后面的点。希望有帮助。

include_once('dbconnect.php');
echo "<form action='delete.php' method='post' id = 'deleteForm'>";

$sqlARTICLEQuery = "SELECT * FROM articles where pageId=$paqueryRow[pageId] order by articleId";
$articlequeryResult = mysqli_query($conn,$sqlARTICLEQuery);
while ($articlequeryRow = mysqli_fetch_assoc($articlequeryResult))
{ echo "<input type = 'radio' name = '$articlequeryRow[articleId]' method = 'post'>".$articlequeryRow['articleId']."&nbsp".$articlequeryRow['articleTitle']."&nbsp";
    echo "<input name='ARTSubmit' type='submit' value='delete record' /><br/>";
    if (isset($_POST['ARTSubmit'])){
        $artDeleteQuery = "DELETE FROM articles where pageId = $paqueryRow[pageId] AND articleId=$articlequeryRow[articleId].";

        if(mysqli_query($conn, $artDeleteQuery)){
            echo "Record deleted successfully";
        } else {
            echo "Error deleting record: " . mysqli_error ($conn);
        }
    }
$sqlTEXTQuery = "SELECT * FROM text where articleId=$articlequeryRow[articleId] order by textId";
$textqueryResult = mysqli_query($conn,$sqlTEXTQuery);                   
while ($textqueryRow = mysqli_fetch_assoc($textqueryResult))
    {
        echo "<input type = 'radio' name = '$textqueryRow[textId]' method = 'post'>".$textqueryRow['textId']."&nbsp".$textqueryRow['textTitle']."&nbsp";         //how can I print articles.pageId to match with pages.pageId
        echo "<input name='TEXTSubmit' type='submit' value='delete   record' /><br/>";
        if (isset($_POST['TEXTSubmit'])){
            $textDeleteQuery = "DELETE FROM text where articleId = $articlequeryRow[articleId] AND textId = $textqueryRow[textId].";

            if(mysqli_query($conn, $textDeleteQuery)){

                echo "Record deleted successfully";
            } else {
                echo "Error deleting record: " . mysqli_error ($conn);
            }
        }echo "<br />"
    }echo "<br />"
}echo "</form>"
$conn->close();
?>

关于php - 如何删除一行而不是所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47090457/

相关文章:

javascript - ajax 用 facebook-Java 加载 php 不工作

php - 警告 : imagejpeg() [function:imagejpeg]: gd-jpeg: JPEG library reports unrecoverable error

php - 如何在 laravel 中使用 mysql DATE_SUB?

php - 我应该回滚失败的 SELECT 语句还是提交成功的语句?

html - 将 Now() 插入 MYSQL

mysql - apt-get update 更新mysql失败

mysql - unix_timestamp 未返回预期输出

javascript - 使用 jQuery 检测页面上的所有数据是如何完成的?

php - 如何从标签和项目表中获取所有可能的组合?

mysql - 根据列值和非重复列选择行