Affiliate Marketing
Forum Search

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 14-08-06
Wardy's Avatar
This is the one
 
Join Date: Aug 2003
Posts: 2,747
Thanks: 14
Thanked 0 Times in 0 Posts
Wardy is an unknown quantity at this point
  php search problem

Got another what I think is a simple coding question.
I have a search on one of my sites that includes a drop down menu ($searchpr) and also a search box ($searchprname) that both get filled in when a user searches.

The pageis called search.php and the search results get displayed back on search.php too.
Some records have "favpr" and "prusername" blank and these are gettign displayed on the search.php page before a search has been done.
What do I need to do to stop this?

PHP Code:

$searchpr 
$_GET["searchpr"];
$searchprname $_GET["searchprname"];

    
$query  "SELECT * FROM players WHERE favpr ='$searchpr' AND prusername LIKE '%$searchprname%' ORDER BY username";
    
$result mysql_query($query) or die("Error: " mysql_error()); 

    if(
mysql_num_rows($result) == 0){ 
        echo(
""); 
    } 
I hope that makes sence?!

Cheers
Wardy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 14-08-06
Registered User
 
Join Date: Aug 2005
Posts: 121
Thanks: 0
Thanked 1 Time in 1 Post
haggul is an unknown quantity at this point
If it's a self calling page add a hidden field into your form called perhaps Mode and with a hard coded value of "Search"

Then wrap an if statement around the code that builds and runs the query that checks for $_GET["Mode"]=="Search" - i.e. so the page won't do anything until it has first been submitted.

At the moment it's running the query regardless I imagine, and the lack of anything in those variables means you get all records where those fields are blank - i.e. it's returning exactly what it's being asked to.
__________________
haggul
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 14-08-06
Super Moderator
 
Join Date: Aug 2003
Posts: 2,451
Thanks: 0
Thanked 0 Times in 0 Posts
Rich is an unknown quantity at this point
If you want the user to be able to search for the blank records then add a hidden field to the form and only do the seach if that field is set.

If you will never show those blank fields then do something like: -
PHP Code:
if (($searchpr!='') || ($searchprname!='')) { 
  
//do search and show results,
} else {
  
// don't do search

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 14-08-06
Wardy's Avatar
This is the one
 
Join Date: Aug 2003
Posts: 2,747
Thanks: 14
Thanked 0 Times in 0 Posts
Wardy is an unknown quantity at this point
Haggul & Rich nice one
Exacly what I needed, it now works

Cheers
Wardy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #5 (permalink)  
Old 14-08-06
Technophobe Geek
 
Join Date: Jan 2005
Location: Cumbria, UK
Posts: 482
Thanks: 0
Thanked 1 Time in 1 Post
trevHCS is an unknown quantity at this point
Erm, on a slight side note, you do sanitise the users input before putting it into the database query, don't you? Eg: at the very least:

http://uk.php.net/manual/en/function...ape-string.php

Or as we preach at the Ministry of Geek - users are dumb creatures and will always set out to break your system by doing really stupid things.

Trev
__________________
UK Hotel :: UK Cottage :: UK Attraction :: Mad Theories
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
My Keyword Research - Care to contribute to the research? webdesignhq Search Engine Strategies 4 26-03-07 09:52 AM
Search Engine Strategies Banner-Traffic Search Engine Strategies 0 10-08-06 10:51 PM
Seach Engine Optimisation FAQ [Jan2006] thetafferboy Organic Google Search Optimisation 2 09-01-06 05:11 PM
MSN announced a redesign for its MSN Search service getvisible The Affiliate Marketing Lounge 0 25-03-04 10:41 PM
ARELIS 3 Link Popularity Software Qui Gon Jinn Website Promotion 4 05-03-03 07:34 AM


Affiliate Marketing RSS Feeds - Contact Us - Affiliate Marketing - Archive - Privacy Statement - Top

Content Relevant URLs by vBSEO 3.2.0 RC7