Unstoppable Domains

Help with search

Spaceship Spaceship
Watch

Isaac1

Established Member
Impact
1
I'm having a problem with a search I'm coding. Here are the contents of the files:

srch.php
Code:
<?php

include("config.php");
 
if ($search) // perform search only if a string was entered. 
{ 
mysql_connect() or die ("Problem connecting to Database"); 
$srch="%".$search."%";
$query = "select * from phpbb_forums WHERE forum_name like '$srch'"; 

$result = mysql_db_query("isaac_fortgamer", $query); 

if ($result) 
{ 
echo "Here are the results:<br><br>"; 
echo "<table width=90% align=center border=1><tr> 
<td align=center bgcolor=#00FFFF>Forum Name</td> 
</tr>"; 

while ($r = mysql_fetch_array($result)) { // Begin while 
$fname = $r["forum_name"]; 
echo "<tr> 
<td>$fname</td> 
</tr>"; 
} // end while 
echo "</table>"; 
} else { echo "problems...."; } 
} else { 
echo "Search string is empty. <br> Go back and type a string to search"; 
} 
include ('links.x'); 
?>

search.php
Code:
<html> 
<head><title>Searching the Forums</title> 
</head> 
<body bgcolor=#ffffff> 
<h1>Searching the Database</h1> 
<form method="post" action="srch.php"> 
<table width=90% align=center> 
<tr><td>search for:</td><td><input type=text name='search' size=60 maxlength=255></td></tr> 
<td></td><td><input type=submit></td></tr> 
</table> 
</form> 
<?php include ('links.x');?> 
</body> 
</html>

Everytime I try to do a search, it tells me that no search string was entered. Can anyone please help me figure out what I'm doing wrong?

Thanks!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
Change
if ($search)
To
if ($_POST['search'])
 
0
•••
Great, now the search seems to work. The thing is, it doesn't seem to be actually searching. It appears that it just lists the two forums I already have, no matter what I search for. Is there something I'm doing wrong that would cause this?

Edit: Here is the search, so you can see what I mean.
 
0
•••
Try changing
PHP:
<?php

include("config.php");
 
if ($search) // perform search only if a string was entered. 
{ 
mysql_connect() or die ("Problem connecting to Database"); 
$srch="%".$search."%";
$query = "select * from phpbb_forums WHERE forum_name like '$srch'";
to
PHP:
<?php

include("config.php");

$search = mysql_real_escape_string( trim( $_POST['search'] ) );

if ($search) // perform search only if a string was entered. 
{ 
mysql_connect() or die ("Problem connecting to Database"); 
$srch = "%".$search."%";
$query = "select * from phpbb_forums WHERE forum_name like '$srch'";
 
0
•••
That works! Thanks a lot, I really appreciate it.
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back