Re: MySQLI, Class not found

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



when i try it this way:
 
<?php
 
// create short variable  names
$searchtype=$_POST['searchtype'];
$searchtype=$_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', 'root', 'root', 'bookorama');
 
 
 
if(mysqli_connect_errno())
{
echo 'Error: Could not connect to  the Database. Please try again later.';
exit;
}
 
$query = "select * from books where ".$searchtype." like  
'%".$searchterm."%'";
$result = $db->query($query);
 
$num_results = $result->num_rows;
 
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>';
}
var_export($result);
$result->free();
$db->close();
 
?>
 
It doesn't even try searching the database... it gives me  the:  'You have 
not entered search details. Please go back and try  again. Error.
 
when i comment out the IF statement and add the  var_export($result) (just to 
see what it happens) it gives me this  error:
 
===============================================
Number of books found: false
Fatal error: Call to a  member function free() on a non-object in 
c:\wamp\www\books\results.php  on line 56 
===============================================
 
the HTML code is:
 
===============================================
<form action="results.php" method="post">
Choose Search  Type: <br />
<select  name="searchtype">
<option  value="author">Author</option>
<option  value="title">Title</option>
<option  value="isbn">ISBN</option>
</select>
<br  />
Enter Search Term:<br />
<input  name="searchterm" type="text">
<br />
<input  type="submit"  value="Search">
</form>
================================================
 
maybe i'm just tired and not seeing something - but i've looked a thousand  
times and i have no clue why it's doing this... searches on google prove 
nothing  either.
 
Server Configuration 
    Apache version : Apache/1.3.33 (Win32) (WIN XP)  PHP version : 5.0.4  
MySQL version :  
5.0.7-beta-nt - extension : mysqli
 
Thanks again,
 
Clint


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux