0

I am currently trying to develop my A-level computer science project so I can document it, however I am stuck on how to get some of my code to be entered into my database - it was working but I added a few bits to it and it stopped working when I was pressing the 'submit' link, the code that connects and adds to my database is shown:


    if(isset($_POST['quiz'])) {

        $name = $_POST['name'];
        $question = $_POST['question'];
        $answer = $_POST['answer'];


        $dbc = mysqli_connect("","","","") or die('Error connecting to MySQL server')
            $query = "INSERT INTO Quiz(name, question, answer) VALUES('$name', '$question', '$answer')";
            $result = mysqli_query($db, $query) or die('Error querying database.');
            mysqli_close($db);
    }
    echo "1 record added";

?>

Obviously I have all the details in the $dbc to connect to my database, I am a beginner with PHP and I am trying to get my head around why it isn't working, any help would be appreciated.

Zhorov
  • 28,486
  • 6
  • 27
  • 52
  • `$dbc` or `$db` is the variable, holding the connection? And, always try to use parameterized statements to prevent SQL injection. – Zhorov Mar 21 '20 at 10:54
  • yes, thats my connection to the database, haven't included all my details in it though, but the connection does work as it was working before I changed the structure of it. –  Mar 21 '20 at 10:56

0 Answers0