I am new to this, and I am stumed on what seems to be a stupid problem, that I just can’t figure out. I am searching a mysql database. Everything so far is fien but I am geting an error. The error reads: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/digitalo/public_html/exp/bookorama/results.php on line 32
Not sure why this is happening, everything looks iek it shoudl work. I am getting this code from a book.
<html>
<head>
<title>Search Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
Book-O-Rama Search Results<br>
<?
trim($searchterm);
if (!$searchtype || !$searchterm){
echo "You did not fill our the required fields<br>";
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
@ $db = mysql_pconnect("localhost", "USERNAME", "USERPASS");
if (!db){
echo "Error: COuld notconnect to database.";
exit;
}
mysql_select_db("digitalo_bookstore");
$query = "select * from books where ".$searchtype." like
'%".$searchterm."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo "<p>Number of books found: ".$num_results."</p>";
for ($i=0; $i <$num_results; $i++){
$row = mysql_fetch_array($result);
echo "<p><strong>".($i+1).". Title: ";
echo htmlspecialchars( stripslashes($row["title"]));
echo "</strong><br>Author: ";
echo htmlspecialchars (stripslashes($row["author"]));
echo "<br>ISBN: ";
echo htmlspecialchars (stripslashes($row["isbn"]));
echo "<br>Price: ";
echo htmlspecialchars (stripslashes($row["price"]));
echo "</p>";
}
?>
</body>
</html>
They are priceless. They have helped me so much. All of my knowledge of PHP and mySQL manipulation pretty much began with that and in just a week or so I was create full control panels for websites. Together the price is about $50 but don’t whine about spending the money because they are worth every penny. mdipicom bought the PHP after I recommended it to him and he loved it. If you have 3/4 of a brain cell you will understand PHP when you get done with those books.
Actually the first one is all you really need because it actually explains the basics of php/mysql all in one, but the second book helps with more specific areas of the mysql.
thanks a lot for the info, its late so i wont be able to check the code until tomorrow, but i’ll def let you know if it works. yea im not sure if i am even getting a connection to my db, but i overlooked the error you pointed out, so that is probably what is wrong. I know asp pretty well, but php just seems so much more powerful that i had to try and learn it, and its really not much different than connecting to db’s using asp, same concept. i will take a look at those books, i just bought one called php and mysql web development by SAMS. i dont mind spending $$ on this stuff, as this is my how i make my $$ gotta lose money to make money…
anyway thanks again, and ill let you know the verdict tom…
ok well i just couldnt wait to test it, it seems that i am not connecting to my database, not sure why. i am going to take a step back and see what the problem is.
ok i am not connecting to my db, and i am also gettng that same error. starting to piss me off. could this have to do with the creation of the database? this is my first time building a mysql db as well as accessing it from the web. also this is running off a web server, not my pc. any configuring i should know about?
not really, but you might want to check with your server to see how they want you to connect. Sometimes local host might not work…
also, are you sure the user and pass are correct? because you usualy would have to create a user specifically for that database. Your username and password for your actual website wouldn’t work in this case…
i pmed you my aim sn. whats interesting is when i run query’s from the db its self everything works fine. but when i try to access via php there is a problem