Multiple choice game This is a multiple choice game. It has a web page where you enter a question, which can have multiple answers along with multiple options.

Can anyone recommend any improvements for my code?

//correct &amp; options are both arrays. These arrays are being passed through an AJAX call
function addQuestion($topicID, $difficulty, $isMultiple, $quest,$correct, $options){
    global $numRecords,$dbConnection,$stmt;
    connect();

    //Insert into question table &amp; recieve the question ID for use in the answers insert stmt
     $sql = "INSERT INTO question (topic_ID,difficulty,isMultiple, question)
            VALUES($topicID,$difficulty,$isMultiple,'$quest');";
    try{
        $stmt=$dbConnection-&gt;query($sql);
            $qID = $dbConnection-&gt;lastInsertId();

        if(!$stmt)
            die("error1".$dbConnection-&gt;errorInfo());
        $stmt = "";

        for($i = 0; $i &lt; sizeof($correct); $i++):
            $stmt .= "INSERT INTO answer (question_ID, data, isCorrect)
                VALUES($qID,'".$correct[$i]."',1);";
        endfor;

        for($z = 0; $z &lt; sizeof($options); $z++):
            $stmt .= "INSERT INTO answer (question_ID, data, isCorrect)
                VALUES($qID,'".$options[$z]."',0);";
        endfor;
        $dd = $dbConnection-&gt;query($stmt);

        if(!$dbConnection)
            die("error2".$dbConnection-&gt;errorInfo());               

    }catch (Exception $e){
        //Rollback if fails
        $dbConnection-&gt;rollback();
        return "Error rolling back: ". $e;
    }
}
Your code is vulnerable to sql-injection.  For example, if $quest contains a ' character, your INSERT will break.