Возникла проблема с удалением строк с сервера - PullRequest
0 голосов
/ 28 марта 2019

Таким образом, у меня возникли проблемы с получением кода для удаления строк из таблицы базы данных "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 ]

1 голос
/ 28 марта 2019

в этой строке

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

заменить $qID на $getDropdownID, потому что я не вижу, где $qID получить значение.

0 голосов
/ 28 марта 2019

Спасибо, что посмотрели, у меня был небольшой пердеж, и я назвал неправильную переменную в подготовленном утверждении, исправление было

$SQL_stmt->bind_param("i", $getDropdownID);
...