I am trying to setup a website that you can store and search for user profiles. I want to be able to search by last name, display the list of user(s) that match that last name and then be able to select one of those users from the list to display their full profile.
I have created a page called search_user.php that includes a form with one input textfield used for searching the last name.
search_user.php
- Code: Select all
<form name="member" method="post" action="results_user.php">
Please enter the last name of the user:
<input name="search" type="text" id="search">
<input name="submit" type="submit" id="submit" value="Search" />
</form>
My next page displays a list of users that match that last name. Currently it echos their last name and first name. Their last name is a hyperlink which would ideally go to their full profile.
results_user.php
- Code: Select all
<?php
if(isset($_POST['search']))
{
mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die("Can't connect to database");
mysql_select_db(DB_DATABASE) or die(mysql_error());
#Convert to upper case, trim it, and replace spaces with "|":
$search = (ini_get('magic_quotes_gpc')) ? stripslashes($_POST['search']) :
$_POST['search'];
$search = mysql_real_escape_string($search);
$search = strtoupper(preg_replace('/\s+/', '|', trim($_POST['search'])));
#Create a MySQL REGEXP for the search:
$regexp = "REGEXP '[[:<:]]($search)[[:>:]]'";
$query = "SELECT * FROM `users` WHERE UPPER(`lastname`) $regexp";
$result = mysql_query($query) or die($query . " - " . mysql_error());
if(mysql_num_rows($result) <= 0){echo "No Results Found - Please try your search again.";}
while($row = mysql_fetch_array($result))
{
echo "<a href=profile_member.php>".$row['lastname']. "</a> ";
echo $row['firstname'];
echo "<br>";
}
}
?>
What I am having trouble with is how to click on the last name and display that user's profile information from the mysql database?
Any help would be appreciated!

