0

I have a database with two rows of filler information filled in at the moment. I want to pull some information for up to 10 rows of this database.

My PHP looks like this:

$sql = $db->prepare("SELECT questionText, correctAnswer, wrongA, wrongB, wrongC, topic FROM quizquestions WHERE lang = ? ORDER BY RAND() LIMIT 10;"); //Pulls 10 random questions
$sql->bind_param("s", $lang);

$sql->execute();
$result = $sql->get_result();

if ($result === FALSE){
    echo("<html><body><h1> Error: Query unsuccessful </h1> <p>Arc Code are sorry for the inconvinience, please try again later  </p></body></html>");
    return 0;

}

if ($result -> num_rows <= 0){
    echo("<html><body><h1> Error: No questions found for that language </h1> <p>Arc Code are sorry for the inconvinience, please try again later </p></body></html>");
    return 0;
}

while ($row = $result->fetch_assoc()){
    echo("success");
    //etc
}

Every time it runs I end up caught at the "No questions for that language" error, however when I run the query through SQLTools in VSCode I get the two rows of sample data I inputted.

For the example I'm running, $lang is equal to either J or P and is recieved from a html form. However changing it to a constant string, as I have to do in SQLTools doesn't change the output.

0 Answers0