VickP07
10-24-2011, 11:50 PM
Hey guys so i am trying to write is a PHP web service page to search for users. It should respond to HTTP GET
requests and take a string to search for as a query string variable. It should return the username, first_name and
last_name of all users who have that search string as part of their username, first_name or last_name.
So right now I open my page:
paguilary/test/find-user2.php
and then at the end of the string i add ?username=et
I should get "etomai" and also any other user with "et" anywhere, in their username, first name or last name.
Right now i am just testing to see if the users that end in whatever i type at the end of the string will work....but i am BEYOND LOST as to how to display all the users that might have 'et' anywhere in their username.....
Right now in my if statement my sql query is correct its the displaying part taht I dont know how to do.
here is my code:
<?php
$db = mysql_connect( "localhost","root", "temp1234");
mysql_select_db( "csci3342");
$user = $_GET['username'];
$firstname = $_GET['first_name'];
// start xml document
header( "Content-type: text/xml" );
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<value>
<?
if( $user )
{
$sql = "
SELECT username FROM users
WHERE username like '%$user%';
";
echo "<UserName>" . $sql. "</UserName>\n";
} else if( $firstname ) {
echo "<FirstName>" . $firstname . "</FirstName>\n";
}
?>
</value>
requests and take a string to search for as a query string variable. It should return the username, first_name and
last_name of all users who have that search string as part of their username, first_name or last_name.
So right now I open my page:
paguilary/test/find-user2.php
and then at the end of the string i add ?username=et
I should get "etomai" and also any other user with "et" anywhere, in their username, first name or last name.
Right now i am just testing to see if the users that end in whatever i type at the end of the string will work....but i am BEYOND LOST as to how to display all the users that might have 'et' anywhere in their username.....
Right now in my if statement my sql query is correct its the displaying part taht I dont know how to do.
here is my code:
<?php
$db = mysql_connect( "localhost","root", "temp1234");
mysql_select_db( "csci3342");
$user = $_GET['username'];
$firstname = $_GET['first_name'];
// start xml document
header( "Content-type: text/xml" );
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<value>
<?
if( $user )
{
$sql = "
SELECT username FROM users
WHERE username like '%$user%';
";
echo "<UserName>" . $sql. "</UserName>\n";
} else if( $firstname ) {
echo "<FirstName>" . $firstname . "</FirstName>\n";
}
?>
</value>