General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old June 17th, 2003, 05:06 PM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
search script problems!

I am trying to write a php page for searching the user database for specific users. This is what I have so far.

PHP Code:
<?php require_once('Connections/users.php'); ?>
<?php
mysql_select_db
($database_users$users);
$query_Recordset1 "SELECT * FROM users";
$Recordset1 mysql_query($query_Recordset1$users) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);

if(
$_POST['search'])
    {
        
$_POST['search'] = $search;

      
//this was me doing some error checking;
        
echo $search;
        echo 
$_POST['search'];

        
$findUser mysql_query("SELECT * FROM users WHERE username = '" $search "'");
            while (
$findUser2 mysql_fetch_row($findUser))
                      {global 
$findUser2;
                        echo 
'hello';
                        echo 
'<a href="index.php?page=viewprofile&userid=' $findUser2[0] . '">' $findUser2[2] . '</a><br>';
                    } } else { 
?>


<form action="index.php?page=search&search=1" method="post" name="search" target="_self">
<input name="search" type="text" value="[enter search term here]" size="30" maxlength="25">
<input name="submit" type="submit" value="Search!">
</form>
<?php 
mysql_free_result($Recordset1);
?>

this is giving me nothing at all. The error chbecking I did isn't evem echoing hte $POST_['search']. any ideas? I am an amatuer and don't know much about php or forms yet. Thanks for your time!
__________________
hey it's the CHARKING

Reply With Quote
  #2  
Old June 17th, 2003, 05:15 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
heres you problem

PHP Code:
 $_POST['search'] = $search;

//this was me doing some error checking;
echo $search;
echo 
$_POST['search']; 


Heres the way it should be...

PHP Code:
 $search $_POST['search'];

// now these will both work
echo $search;
echo 
$_POST['search']; 


the way you had it,...you were setting $_POST['search'] equal to nothing. Then when you tried to echo nothing, you got nothing
__________________
-- Jason

Reply With Quote
  #3  
Old June 18th, 2003, 03:41 AM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
thanks man

yah i was writting something earlier and realized as I wrote it that that was my problem, cause this time I had written it correctly. So I fixed it and it is echoing stuff now, only I have to clean somethin g up, but it seems good. so thanks

ran into a new problem. small one though.

I want when there is no username matching the search query, it should say something to the user about searching again or whatever. I have tried using and if statement in numerous places and it's jsut not working. I tried using
PHP Code:
if($findUser=="")
{ echo 
" no user blah blah blah search again"; } else { do while statement 

I tried stuff like that. well any suggestions? it seems easy, but every time I try it just gives me a blank page.

Last edited by thecharking : June 18th, 2003 at 04:02 AM.

Reply With Quote
  #4  
Old June 18th, 2003, 09:00 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
PHP Code:
if( !$findUser )
{
     echo 
"no user blah blah blah search again";
}
else
{
     
// do while statement




if it is showing a blank page you may have a parse error somewhere. Post the code that shows how $findUser gets set

Reply With Quote
  #5  
Old June 18th, 2003, 11:41 AM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
the code

not much more really.

PHP Code:
<?php require_once('Connections/users.php'); ?>
<?php
mysql_select_db
($database_users$users);
$query_Recordset1 "SELECT * FROM users";
$Recordset1 mysql_query($query_Recordset1$users) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);

if(
$_POST['search'])
    {
        
$search $_POST['search'];
        
$findUser mysql_query("SELECT * FROM users WHERE username = '" $search "'");
            while (
$findUser2 mysql_fetch_row($findUser))
                      {global 
$findUser2;
                    if(
$findUser2[0] == "")
        { 

//some error checking...
echo 'No User Exists By That UserName!';
          echo 
'Please <a href="index.php?page=search">Search Again!</a>';
                              } else {
                        
header("Location: index.php?page=viewprofile&userid=" $findUser2[0] . "");
                    } } } else { 
?>


<form action="index.php?page=search&search=1" method="post" name="search" target="_self">
<input name="search" type="text" value="[enter search term here]" size="30" maxlength="25">
<input name="submit" type="submit" value="Search!">
</form>
<?php 
mysql_free_result($Recordset1);
?>

Reply With Quote
  #6  
Old June 18th, 2003, 11:51 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
what should the value for $_POST['search'] be? can you echo $_POST['search']? what does it return?

Reply With Quote
  #7  
Old June 18th, 2003, 06:50 PM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
what i get

when i search for something that is in the database, it simply sends me to the profile... i use headers to do it... when i search for something not in the database, i get the search term that i entered. So that's what i expected... oh but by the way... I don't really have this problem anymore because I realized that I won't need to show that little blurb about not having a user, if I were able to pull up all users that match somewhat to the search term... like msot search engines, you know? So how can I do this? you know anything? I appreciate the help.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > search script problems!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway