/    Sign up×
Community /Pin to ProfileBookmark

A Simple Search Form Not Working

I’ve set up a simple search form but on POST it get’s no result, I’ve tested it with data I know is definitely in the database, not sure what I am doing wrong…

[B]Search Form[/B]

[code]<html>
<head>
<title>Search Test</title>
</head>
<body topmargin=”0″ leftmargin=”0″>
<form action=”searchResults.php” method=”post”>
Search Term <input type=”text” name=”searchterm”><br />
<input type=”submit” value=”Search”>
</form>
</body>
</html>[/code]

[B]PHP[/B]

[code=php]<?php
include ‘library/config.php’;
include ‘library/opendb.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);
}

/*query the database*/
$query = “SELECT * FROM `tblmembers` WHERE `FirstName` LIKE ‘%”.$searchterm.”%’ AND `MemberApproved`=’A'”;
$result = mysql_query($query) or die(‘Error, query failed’.mysql_error());

/*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[‘FirstName’]).” <br />”;
}

include ‘library/closedb.php’;
?>[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@derekharveyApr 15.2007 — I can't see any obvious problems, but isn't shouldn't $result->num_rows; be $num_results = $result->num_rows(); as it's a function?

Sorry i can't be any more help ...
×

Success!

Help @tomyknoker spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...