MySQL Forums
Forum List  »  PHP

Error querying database
Posted by: Michael Crowe
Date: April 01, 2016 06:41PM

I am TRYING to learn PHP & mySQL and one of the exercises in the book Im using is to create a form for users to fill in and to insert that into the DB. I have created the DB 'alien_abductions' along with tables. Here is the code I have. Problem: I am getting "Error querying database". Can someone see if I have something wrong in the script? Being new, I am not sure what I am missing.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Alien Abduction</title>

</head>

<body>
<h2>Your Abduction</h2>
<?php
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$when_happened = $_POST['whenithappened'];
$how_long_gone = $_POST['howlongwereyougone'];
$howmany = $_POST['howmany'];
$description = $_POST['description'];
$whattheydid = $_POST['whattheydid'];
$fangspotted = $_POST['fangspotted'];
$email = $_POST['email'];

$dbc = mysqli_connect('localhost','root','','up_and_running')
or die('Error connecting to MYSQL server');

$query = "INSERT INTO alien_abductions (firstname, last_name,
when_happened, howlongwereyougone," .
"howmany, description, whattheydid, fangspotted, email)" .
"VALUES ('$first_name', '$last_name', '$when_happened', '$how_long_gone', '$howmany', '$description', '$whattheydid', '$fangspotted', '$email')";

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

mysqli_close($dbc);

echo 'Thanks for your submission.<br />' . $first_name . '<br />';
echo 'You were abducted ' . $when_happened . '<br />';
echo ' and you were gone for '. $how_long_gone . '.<br />';
echo 'You describe them as: ' . $description . '.<br />';
echo 'You estimated the number of aliens as: ' . $howmany . '<br />';
echo 'You state that they ' . $whattheydid . '.<br />';
echo 'Was Fang spotted? ' . $fangspotted . '<br />';
echo 'We have your email address as ' . $email;






?>

</body>
</html>

Regards,
Mike

Options: ReplyQuote


Subject
Written By
Posted
Error querying database
April 01, 2016 06:41PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.