I am new to using php and Mysql - wow is all I can say.
I have been spending the day setting up my results.php and ran into the following errors.
If you want to see the error first hand visit the site and enter a search. www.plasticsdirectory.com
This is what I get on my results page -
Results found matching your query:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in (leaving out source)results.php on line 78
Company Name:
Category:
Contact Person:
Address1:
Address2:
City, State:
Postal Code:
Country
E mail:
Web Address:
Description:
I have been taking the code straight from a book and it will not take the code for displaying the results.
Here is the orginally code - using this I don't get the Company Name... listing and the error mysql_num_rows():
Here is the complete code as given by the book:
<?php
// create short variable names
$state=$HTTP_POST_VARS['searchtype'];
$keyword=$HTTP_POST_VARS['keyword'];
$keyword= trim($keyword);
if (!$searchtype || !$keyword)
{
echo 'You have not entered search details. Please go back and try again.';
exit;
}
$searchtype = addslashes($searchtype);
$keyword = addslashes($keyword);
// connect to database
@ $db = mysql_pconnect('localhost', 'user', 'pw');
if (!$db)
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
mysql_select_db('plas27');
$query = "select * from plas27 where ".$searchtype." like '%".$keyword."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo '<p>Number of results found matching your query: '.$num_results.'</p>';
for ($i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo '<p><strong>'.($i+1).'. Company Name: ';
echo htmlspecialchars(stripslashes($row['Company_Name']));
echo '<br />Category: ';
echo stripslashes($row['Category']);
echo '<br />Contact Person: ';
echo stripslashes($row['Contact_Person']);
echo '<br />Address1: ';
echo stripslashes($row['Address1']);
echo '<br />Address2: ';
echo stripslashes($row['Address2']);
echo '<br />City, State: ';
echo stripslashes($row['City, State']);
echo '<br />Postal Code: ';
echo stripslashes($row['Postal_Code']);
echo '<br />Country ';
echo stripslashes($row['Country']);
echo '<br />E mail: ';
echo stripslashes($row['E_mail']);
echo '<br />Web Address: ';
echo stripslashes($row['Web_Address']);
echo '<br />Description: ';
echo stripslashes($row['Description']);
echo '</p>';
}
?>
Any help to get this error fixed would be great.
Thanks
Mel