Jump to content


Photo

chpt 2 - "error querying database"


  • Please log in to reply
65 replies to this topic

#61 lemuel

lemuel

    Super Veteran Member

  • Members
  • PipPipPipPipPipPipPipPipPipPipPip
  • 577 posts

Posted 26 December 2011 - 08:41 AM

I believe that has to be:

or die(mysqli_error($dbc));

#62 derajfast

derajfast

    New Member

  • Members
  • Pip
  • 4 posts

Posted 26 December 2011 - 12:09 PM

It's still returning a blank page when I swap that snippet in. Here is my full code now:

<html>
<head>
<title>Aliens Abducted Me - Report an Abduction</title>
</head>
<body>
<h2>Aliens Abducted Me - Report an Abduction</h2>

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

$dbc = mysqli_connect('localhost:8889', 'root', 'root', 'aliendatabase')
or die('Error connecting to MySQL server.');

$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(mysqli_error($dbc));


mysqli_close($dbc);

echo 'Thanks for submitting the form.<br />';
echo 'You were abducted ' . $when_it_happened;
echo ' and were gone for ' . $how_long . '<br />';
echo 'Number of aliens: ' . $how_many . '<br />';
echo 'Describe them: ' . $alien_description . '<br />';
echo 'The aliens did this: ' . $what_they_did . '<br />';
echo 'Was Fang there? ' . $fang_spotted . '<br />';
echo 'Other commentsd: ' . $other . '<br />';
echo 'Your email address is '. $email;

?>

</body>
</html>

#63 lemuel

lemuel

    Super Veteran Member

  • Members
  • PipPipPipPipPipPipPipPipPipPipPip
  • 577 posts

Posted 26 December 2011 - 12:19 PM

You're missing a single quote in your query before what_they_did.

#64 derajfast

derajfast

    New Member

  • Members
  • Pip
  • 4 posts

Posted 26 December 2011 - 12:22 PM

Success! Thank you so much

#65 webdevdea

webdevdea

    New Member

  • Members
  • Pip
  • 9 posts

Posted 03 August 2013 - 02:03 PM

The code in the book should work just fine because i just finished chapter 2. I think you have a different version of either PHP or MySQL installed on your computer. I have installed PHP and MySQL on a MAC therefore I can't tell you exactly what to do,however,if you make sure you have PHP 5 and MySQL 5.0. it should work.<img src="http://forums.oreill...IR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />

I am having the same problem, I am using a mac.. I am having a hard time with it, I have all the latest stuff but ti still cant access the database

#66 PhilipHarper

PhilipHarper

    New Member

  • Members
  • Pip
  • 5 posts
  • Gender:Male
  • Location:London, England
  • Interests:Surfing, Snowboarding, Hiking. Learning new stuff!

Posted 11 July 2014 - 04:43 AM

I literally had the same problem.

I spent HOURS trying to figure it out, thanks for sharing your tip!

How do you ensure that's the user can input ' s in the input field without it breaking the database query is my next question?


Cheers,

Philip




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users