从服务器删除行时遇到问题

时间:2019-03-28 19:38:41

标签: php sql mysqli rowdeleting

简而言之,我在运行代码时遇到问题,无法从数据库表“ tblsurvey”中删除行,没有错误显示,并且似乎可以正确执行该语句,但是在检查表时我发现​​了该行尚未删除。

<?php //set a question from the database V1.0
require '../configure.php'; //required to connect to the DB
//initialising variables
    $qID = ''; //question ID
    $dropDown = ''; //drop down box
    $startSelect = '<select name=drop1>'; //initial value of select
    $endSelect = '</select>'; //end of select
    $fullHTML = ''; //display the dropdown menus options
    $getDropdownID = ''; //on button submit grabs the UID for the questionairre
    $hiddenTag = '';

    $DB = "questonaire"; //must match Database
    $db_isFound = new mysqli(DB_SERVER, DB_USER, DB_PASS, $DB); //connecting to the database see ../configure.php for details 

    //checking if button as been pressed -- needs to redirect to the appropriate questionaire on pressed
    if (isset($_GET['submit'])){
     //initialising the selected questionaire ID  
        $getDropdownID = $_GET['drop1'];
        //display the selected questionaire
        if ($db_isFound){
            $SQL = "DELETE FROM tblsurvey WHERE ID = ?";
            $SQL_stmt = $db_isFound->prepare($SQL);
            if($SQL_stmt){
                $SQL_stmt->bind_param("s", $qID);
                $SQL_stmt->execute();
                print("question has been successfully removed from the database.");

            }else{
                print("There was a problem running your query: row not deleted");
            }

        }else{
           print("error connecting to DB: Question not deleted");
        }
    } 

它正确输出并显示

print("question has been successfully removed from the database.");

但是该行并未从表中删除。

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

在此行

$SQL_stmt->bind_param("s", $qID);

$qID替换为$getDropdownID,因为我看不到$qID在哪里获得价值。

答案 1 :(得分:0)

谢谢您看我有点脑子屁,在准备好的声明中称错误的var为解决方法

$SQL_stmt->bind_param("i", $getDropdownID);
相关问题