Unstoppable Domains

Search help

Spaceship Spaceship
Watch

electricbeat

Account Closed
Impact
0
right, this is the final piece of help i need before my front end of my website is finished, and this is really buggering me.


If you go to ryan.xenka.com/search.php - and search 'Ryan' firstly it gives mysql errors, secondly it doesnt give me an exact match with Ryan, it shows RRyan instead, which is an account aswell.

I need search.php to display exact matches, and also within the name, so searching Ryan could bring up Ryan, rrrrRyan, Ryanz, etc


PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-2" />
<link rel="stylesheet" href="images/style.css" type="text/css" />
<title>MusicInterests</title>
</head>
<body>
    <div class="content">
        <div class="header_right">
            <div class="top_info">
                <div class="top_info_right">
                    <p><?php include("logged.php"); ?></p>                    
                </div>        
            </div>
                    
            <div class="bar">
                <ul>
                    <li class="slogan">Navigation:</li>
<?php include("navigation.php"); ?>
                
                </ul>
            </div>
        </div>
            
        <div class="logo">
            <h1><a href="#" title="The best music on the net!">Music <span class="red">Interests</span></a></h1>
            <p>What are you listening too?</p>
        </div>
        
        <div class="search_field">
            <form method="post" action="search.php">
                <p><span class="grey">Search for a user, example</span> <span class="search">Ryan</span>   <input type="text" name="search" class="search" /> <input type="submit" value="Play!" class="button" /></p>
            </form>
        </div>
        
        <div class="newsletter">
            <p>Subscribe for the Newsletter!</p>
        </div>
        
        <div class="subheader">
            <p><?php include("top.php"); ?></p>
        </div>
        
        <div class="left">
            <div class="left_articles">
                <h2>Search</h2>
                <p><?php
//the config file should connect to mysql.
require("config.php");
    
//select database
mysql_select_db("users");

$search = $_POST["search"];

//assigns the value of the entered search term in to the variable "search"


$result = mysql_query("SELECT * FROM users where username LIKE '%$search%'"); 

//note "username" would be the field the search looks up, so if you searched for "Waffles" it would look up waffles username in the table users.

while($r=mysql_fetch_array($result))
//grabs all the content it found
{    
  
//then change this to match your mysql columns..this will be the information displayed. You could just have username.

   $id=$r["id"];
   $username=$r["username"];
   $email=$r["email"];
//and so on
   
   // then just display the row
   echo "<a href=\"user-$username\">$username</a> <br/>";
}
?> 
</p>
            </div>
        </div>    
        <div class="right">
                        
            <div class="rt"></div>
            <div class="right_articles">
                <p><b>Most viewed</b><br />The most viewed tool allows you too find the 30 most viewed profiles on musicinterests!</p>
            </div>
            <div class="rt"></div>
            <div class="right_articles">
                <p><b>Links</b><br />
                <?php include("links.php"); ?></p>
            </div>
            <div class="rt"></div>
            <div class="right_articles">
                <p><?php include("sponsor.php"); ?></p>
            </div>
        </div>    
        <div class="footer">
            <p><?php include("footer.php"); ?></p>
        </div>
    </div>
</body>
</html>
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
After you assign the db query results to a var:

Code:
while($r=mysql_fetch_array($result))
{

echo out mysql_error() to see what the exact error is.

Code:
echo mysql_error();
 
0
•••
done what you said, it seems to be fixed
 
0
•••
You must have made other changes then because what I told you to do wouldn't have fixed anything whatsoever. Or perhaps you made changes and never uploaded it previously?
 
0
•••
I have no idea lol

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-2" />
<link rel="stylesheet" href="images/style.css" type="text/css" />
<title>MusicInterests</title>
</head>
<body>
    <div class="content">
        <div class="header_right">
            <div class="top_info">
                <div class="top_info_right">
                    <p><?php include("logged.php"); ?></p>                    
                </div>        
            </div>
                    
            <div class="bar">
                <ul>
                    <li class="slogan">Navigation:</li>
<?php include("navigation.php"); ?>
                
                </ul>
            </div>
        </div>
            
        <div class="logo">
            <h1><a href="#" title="The best music on the net!">Music <span class="red">Interests</span></a></h1>
            <p>What are you listening too?</p>
        </div>
        
        <div class="search_field">
<?php include("searchform.php"); ?>
        </div>
        
        <div class="newsletter">
            <p>Subscribe for the Newsletter!</p>
        </div>
        
        <div class="subheader">
            <p><?php include("top.php"); ?></p>
        </div>
        
        <div class="left">
            <div class="left_articles">
                <h2>Search</h2>
                <p>
				We found the following users:<br /><br />
				<?php
//the config file should connect to mysql.
require("config.php");
    
//select database
mysql_select_db("users");

$search = $_POST["search"];

//assigns the value of the entered search term in to the variable "search"


$result = mysql_query("SELECT * FROM users where username LIKE '%$search%'"); 

//note "username" would be the field the search looks up, so if you searched for "Waffles" it would look up waffles username in the table users.

while($r=mysql_fetch_array($result))
//grabs all the content it found
{    
  echo mysql_error();
//then change this to match your mysql columns..this will be the information displayed. You could just have username.

   $id=$r["id"];
   $username=$r["username"];
   $email=$r["email"];
//and so on
   
   // then just display the row
   echo "<a href=\"user-$username\">$username</a> <br/>";
}
?> 
</p>
            </div>
        </div>    
        <div class="right">
                        
            <div class="rt"></div>
            <div class="right_articles">
                <p><b>Most viewed</b><br />The most viewed tool allows you too find the 30 most viewed profiles on musicinterests!</p>
            </div>
            <div class="rt"></div>
            <div class="right_articles">
                <p><b>Links</b><br />
                <?php include("links.php"); ?></p>
            </div>
            <div class="rt"></div>
            <div class="right_articles">
                <p><?php include("sponsor.php"); ?></p>
            </div>
        </div>    
        <div class="footer">
            <p><?php include("footer.php"); ?></p>
        </div>
    </div>
</body>
</html>

thats the code i'm using at the moment so.. lol. How can I make it so if a user doesn't enter any text it echos out a message?
 
0
•••
Code:
$search = $_POST["search"];

// substitute X with an interger - the minimum number of chars you want to be entered
if (strlen($search) < X) {
    echo "You must enter a search term";
} else {
    // run your query and output data here
}
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

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