Go Back   Computer Forums > Web Design | Website Development > Web Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 06-01-2007, 02:51 PM   #11
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,006
Default Re: [PHP] Need Help!

actually no ops:

$keyword =$ r["keyword"];

that line has a space in it where it shouldn't

$keyword =$r["keyword"];


I blame web monkey, since it was copied directly from his post!
__________________

__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 06-01-2007, 04:05 PM   #12
Fully Optimized
 
Join Date: Jun 2005
Posts: 3,275
Send a message via ICQ to DJ Stephen Send a message via AIM to DJ Stephen Send a message via MSN to DJ Stephen Send a message via Yahoo to DJ Stephen
Default Re: [PHP] Need Help!

lol, its my fault, Sorry
__________________

DJ Stephen is offline   Reply With Quote
Old 06-01-2007, 05:56 PM   #13
Site Team
 
David Lindon's Avatar
 
Join Date: Dec 2002
Posts: 15,233
Default Re: [PHP] Need Help!

If its still showing all files, add a line to echo $search to make sure its not blank because if it is MySQL will return all rows otherwise
__________________
[url=http://www.LNXPS.NET]LNXPS.NET - The XPS Library]
David Lindon is offline   Reply With Quote
Old 06-03-2007, 11:40 PM   #14
In Runtime
 
computerpro's Avatar
 
Join Date: Nov 2004
Posts: 231
Default Re: [PHP] Need Help!

Alright thanks alot, however you cleaned up my code but it didnt fix my prob. My prob is when the form is submitted with nothing in the text field it forwards you to the search.php page (like its supposed to do) but it shows every file saved to my table
computerpro is offline   Reply With Quote
Old 06-20-2007, 03:26 AM   #15
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,006
Default Re: [PHP] Need Help!

yes, it would do that...

you are selecting where like.

consider a windows search...
if you search for *.txt you expect every text file to be returned.
if you search for *a* you expect every file to be returned that has an 'a' in it.
if you search for * you expect every file to be returnde...

the wildcard charecter in SQL isn't * it's %

so your query is actualy

return all records like *keyword*

if there is no keyword your search is:

return all records like **

which is all records.
it's not an error on the page!

the only thing that you can do is check to see if the keyword is blank and then escape the whole process.

PHP Code:
<form action="search.php" method="post">
<p align="Center">
<input type="text" name="search" size="15" maxlength="150" value="" />
<input type="image" name="submit" src="search.jpg" width="75" height="18"> 
</p>
</form>  


 


<?php
$search 
$_REQUEST['search'];
if (
$search=='')
{
echo 
"you must specify a search keyword.";
exit();
}

mysql_connect("localhost","db_searcher","abc123"); 
mysql_select_db("db_search"); 


//guard agains injection attack!

    
if( get_magic_quotes_gpc() )
    {
          
$search stripslashes$search );
    }
    
//check if this function exists
    
if( function_exists"mysql_real_escape_string" ) )
    {
          
$search mysql_real_escape_string$search );
    }
    
//for PHP version < 4.3.0 use addslashes
    
else
    {
          
$search addslashes$search );
    }


$result mysql_query("SELECT * FROM product WHERE keyword LIKE '%$search%'");


while(
$r=mysql_fetch_array($result))



$title $r["title"];
$description $r["description"];
$keyword =$ r["keyword"];
$url $r["url"];


echo 
"$title <br> 
$description <br> 
$url <br>";

}
?>
__________________

__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off



All times are GMT -5. The time now is 01:48 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0