Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Feb 19th, 2006, 3:28 PM   #1
MrMan9879
Programmer
 
MrMan9879's Avatar
 
Join Date: Sep 2005
Location: Nanaimo, BC, Canada
Posts: 97
Rep Power: 0 MrMan9879 is an unknown quantity at this point
Send a message via MSN to MrMan9879
Problem accessing MySQL database

I saw a similar topic to mine, but I couldn't find an answer to help mine. I copied code directly out of the book I'm learning from, but it didn't work. Later, I took the book example out of the CD that it came with, but it didn't work either. Basically, instead of giving me a warning it was just a blank screen except for the header in the <h1> tags. Here is my code:
[PHP]
<html>
<head>
<title>Book-O-Rama Search Results</title>
</head>
<body>
<h1>Book-O-Rama Search Results</h1>
<?php

// create short variable names
$searchtype=$_POST['searchtype'];
$searchterm=$_POST['searchterm'];

$searchterm= trim($searchterm);

if (!$searchtype || !$searchterm)
{
echo 'You have not entered search details. Please go back and try again.';
exit;
}

if (!get_magic_quotes_gpc())
{
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
}

@ $db = new mysqli('localhost', 'bookorama', 'bookorama123', 'books');

if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}

$query = "select * from books where ".$searchtype." like '%".$searchterm."%'";
$result = $db->query($query);

$num_results = $result->num_rows;

if ($num_results == 0 )
{
echo '<p>No results were found.</p>';
}
else {

echo '<p>Number of books found: '.$num_results.'</p>';

for ($i=0; $i <$num_results; $i++)
{
$row = $result->fetch_assoc();
echo '<p><strong>'.($i+1).'. Title: ';
echo htmlspecialchars(stripslashes($row['title']));
echo '</strong><br />Author: ';
echo stripslashes($row['author']);
echo '<br />ISBN: ';
echo stripslashes($row['isbn']);
echo '<br />Price: ';
echo stripslashes($row['price']);
echo '</p>';
}

$result->free();
$db->close();

}
?>
</body>
</html>[/PHP]

I removed the @ on the @ $db, and it did give me an error, and this was it:

Quote:
Fatal error: Class 'mysqli' not found in d:\Apache\Apache\htdocs\results.php on line 27
I am not sure why it doesn't work, and it doesn't make sense to me... since it is right out of the book (and you would think that they woudl have tested their examples...) I figure that it isn't a problem with the setup of the database, because I used the SQL files out of the CD for this example. If someone can tell me why this isn't working, I would greatly appreciate it.
MrMan9879 is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:19 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC