Web Design Forum  
 
Go Back   Web Design Forum > Web and Graphic Design > Web Design

Reply
 
LinkBack Thread Tools Display Modes
Old 06-13-2010, 07:14 PM   #1
New Member
 
Join Date: May 2010
Posts: 8
Unhappy Urgent PHP MySQL help needed!!!

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!
agw567 is offline   Reply With Quote


Old 06-14-2010, 06:11 AM   #2
Bronze Member
 
Join Date: May 2010
Posts: 81
Default

I will check this and update you soon. It needs a test run.
emilyl is offline   Reply With Quote
Reply

Tags
database, error, mysql, php, search

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
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 05:17 PM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.