0

所以简而言之,当我运行代码时,我在让我的代码从我的数据库表“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.");

但是该行不会从表中删除。

任何帮助将不胜感激。

4

2 回答 2

1

在这一行

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

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

于 2019-03-28T19:47:54.130 回答
0

感谢您查看我有一点脑子放屁,并且在准备好的语句中调用了错误的 var 修复是

$SQL_stmt->bind_param("i", $getDropdownID);
于 2019-03-28T20:09:24.437 回答