electricbeat
Account Closed
- Impact
- 0
PHP:
<?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"];
$location=$r["location"];
$song1=$r["song1"];
$song2=$r["song2"];
$song3=$r["song3"];
$song4=$r["song4"];
$song5=$r["song5"];
$song6=$r["song6"];
$song7=$r["song7"];
$song8=$r["song8"];
$song9=$r["song9"];
$song10=$r["song10"];
$artist1=$r["artist1"];
$artist2=$r["artist2"];
$artist3=$r["artist3"];
$artist4=$r["artist4"];
$artist5=$r["artist5"];
$artist6=$r["artist6"];
$artist7=$r["artist7"];
$artist8=$r["artist8"];
$artist9=$r["artist9"];
$artist10=$r["artist10"];
//and so on
// then just display the row
echo "Username: <i>$username</i><br />
Location: <i>$location</i><br />
Email: <i>$email</i><br><br>
<b>Music Interests</b><br />
1. $artist1 - <i>$song1</i><br />
2. $artist2 - <i>$song2</i><br />
3. $artist3 - <i>$song3</i><br />
4. $artist4 - <i>$song4</i><br />
5. $artist5 - <i>$song5</i><br />
6. $artist6 - <i>$song6</i><br />
7. $artist7 - <i>$song7</i><br />
8. $artist8 - <i>$song8</i><br />
9. $artist9 - <i>$song9</i><br />
10. $artist10 - <i>$song10</i><br />";
}
?>
So, I have a form that processes this file(search.php). If I type nothing in the form and push enter, I get all the results for all usernames. Instead I would prefer it to say ' You must enter text too search '. Also, when I search something that isn't in the database, and it's not found I don't have any error message. How could I make it so it returns ' No result found '.
All help appreciated.






