Problem with querying database in mysql 5.7.26 : <p>I am learning php and mysql, and I'm currently reading a book where I'm trying out the examples on my own webserver.</p>

<p>I had no problem setting up the database I'm using, and the code I am using to insert new rows into my database table works perfectly when I test it by writing directly in the INSERT code the values I want to insert. However, when I try to insert variables from $_POST into the mysql INSERT code, I get an error. I have no problems connecting to the database, but the query does not work. There should not be anything wrong with the variable names, because I am able to echo all of them.
I have looked at my code 10 times, and I do not understand what is wrong with it. Does anyone know?</p>

<pre><code>&lt;?php
$when_it_happened = $_POST['whenithappened'];
$how_long = $_POST['howlong'];
$alien_description = $_POST['aliendescription'];
$fang_spotted = $_POST['fangspotted'];
$email = $_POST['email'];
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$name = "$first_name $last_name";
$how_many = $_POST['howmany'];
$what_they_did = $_POST['whattheydid'];
$other = $_POST['other'];

// Posting to database

$dbc = mysqli_connect('localhost', 'root', '', 'aliendatabase')
or die('Problems connecting to database');

$query = "INSERT INTO aliens_abduction (first_name, last_name, when_it_happened, how_long, " .
"how_many, alien_description, what_they_did, fang_spotted, other, email) " .
"VALUES ('$first_name', '$last_name', '$when_it_happened', '$how_long', " .
"'$how_many', '$alien_description', '$what_they_did', '$fang_spotted', '$other', '$email')";

$result = mysqli_query($dbc, $query)
or die('Problems querying database');

mysqli_close($dbc);
?&gt;
</code></pre>

<p>I am getting the error message 'Problems querying database'</p>
