Urgent PHP MySQL help needed!!!

agw567

New Member
OK, I'm getting really annoyed with this...

I'm a complete newbie to PHP and I want to search a database which I have. I am using this code from this website, as advised in another thread:



http://www.knowledgesutra.com/forums...-and-php-code/


<html>
<head>
<title>Search Test</title>
</head>
<body topmargin="0" leftmargin="0">
<form action="search.php" method="post">
Search Term <input type="text" name="searchterm"><br />
<input type="submit" value="Search">
</form>
</body>
</html>



<?php
/*set varibles from form */
$searchterm = $_POST['searchterm'];
trim ($searchterm);
/*check if search term was entered*/
if (!$searchterm){
echo 'Please enter a search term.';
}
/*add slashes to search term*/
if (!get_magic_quotes_gpc())
{
$searchterm = addslashes($searchterm);
}

/* connects to database */
@ $dbconn = new mysqli('host', 'username', 'password', 'database');
if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
/*query the database*/
$query = "select * from tablename where tablerow like '%".$searchterm."%'";
$result = $dbconn->query($query);
/*number of rows found*/
$num_results = $result->num_rows;

echo '<p>Found: '.$num_results.'</p>';
/*loops through results*/
for ($i=0; $i <$num_results; $i++)
{
$num_found = $i + 1;
$row = $result->fetch_assoc();
echo "$num_found. ".($row['tablerow'])." <br />";
}
/*free database*/
$result->free();
$dbconn->close();
?>



I removed the $result->free(); command because it caused an error, now there are no errors, it just never returns a result and says Found:

I need a table to display the results, any table, or any way to display the information, desperately!!!

The MySQL table structure is:

Name: Code: Price: Quantity in Stock:






Please!!! :(


Thanks!
 
Top