Hi all,
This is my first post in the forum and I'm really hoping someone can help me. I've been trying to do this all day and I'm getting nowhere.
Basically I want an admin to be able to search for a single user in site_users sql table using a search box. I want the admin to be able to search users by name, username, email or whatever and have the results returned in a form that can be edited.
I know I need to use an sql LIKE statement but every code I've tried just dosen't seem to work. I'm new at php and I've been able to work my way through but this simple database search is defeating me. If anyone can give me simple php code that I can build on I would be eternally grateful. So if someone wants to do their good deed for the day, helping me would definately be it.
Thanks in advance for any help.
PS I know I should give some code as it might makes things clearer but unfortunately this code I've used returns every user in the table instead of one.
PHP Code:<form method=post action="search2.php">
Search For:
<p>
User Name: <input type=text name=user size=25 maxlength=25>
<p>
Name: <input type=text name=name size=25 maxlength=25>
<p>
Email: <input type=text name=email size=25 maxlength=25>
<p>
<p>
County: <input type=text name=county size=25 maxlength=25>
<p>
<input type=submit>
</form>
<?php
$db = mysql_connect('localhost', 'root', '') or
die ('Unable to connect. Check your connection parameters.');
mysql_select_db('dvdff2', $db) or die(mysql_error($db));
if ($username == "")
{$username = '%';}
if ($name == "")
{$name = '%';}
if ($email == "")
{$email = '%';}
if ($county == "")
{$county = '%';}
$result = mysql_query ("SELECT * FROM site_users
WHERE username LIKE '%$username%'
OR name LIKE '%$name%'
OR email LIKE '%$email%'
OR county LIKE '%$county%'
");
if ($row = mysql_fetch_array($result)) {
do {
PRINT "<b>Username: </b> ";
print $row["username"];
print (" ");
print ("<br>");
PRINT "<b>Name: </b> ";
print $row["name"];
print ("<p>");
PRINT "<b>Email: </b> ";
print $row["email"];
print ("<p>");
PRINT "<b>County: </b> ";
print $row["county"];
print ("<p>");
} while($row = mysql_fetch_array($result));
} else {print "Sorry, no records were found!";}
?>




Reply With Quote


Bookmarks