Jump to content

searching sql from a form


contra10

Recommended Posts

I have a form set up to show results of a query

 

(isset($_POST['submit'])) { 

$postuser = "{$_POST['username']}";
$country  = "{$_POST['country']}";
$postsex = "{$_POST['sex']}";

$query = "SELECT * FROM users WHERE username = '$postuser' AND country = '$country' AND sex ='$postsex'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);

$user = "{$row['id']}";
$userq = "{$row['username']}";
$mycountry = "{$row['country']}";
$sex = "{$row['sex']}";
$city = "{$row['city']}";


echo "<TABLE width=600 bgcolor=black border=1 align=center cellpadding=4 cellspacing=0>"; 
echo "<tr>"; 
    echo  "<td width='35%'><a style='text-decoration:none' href='http://localhost/profile/index.php?user=$user'><FONT FACE='ariel' SIZE='2'>$userq<p>";
echo "$city, $mycountry $sex</a></FONT></td>";
echo "</tr>";
}

 

The thing is that its not working, well it works but only for the first condition, I can't seem to put in another condition and query that search...say for example if someone selected the sex and country, how can i show that as well, I tried defining vairiables and put variables equal to post but i can't seem to make it work please help

Link to comment
https://forums.phpfreaks.com/topic/136904-searching-sql-from-a-form/
Share on other sites

here is the code

 

if (isset($_POST['submit'])) { 

$postuser = "{$_POST['username']}";
$country  = "{$_POST['country']}";
$postsex = "{$_POST['sex']}";

$query = "SELECT * FROM users WHERE username = '$postuser' AND country = '$country' AND sex ='$postsex'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);

$user = "{$row['id']}";
$userq = "{$row['username']}";
$mycountry = "{$row['country']}";
$sex = "{$row['sex']}";
$city = "{$row['city']}";


echo "<TABLE width=600 bgcolor=black border=1 align=center cellpadding=4 cellspacing=0>"; 
echo "<tr>"; 
    echo  "<td width='35%'><a style='text-decoration:none' href='http://localhost/profile/index.php?user=$user'><FONT FACE='ariel' SIZE='2'>$userq<p>";
echo "$city, $mycountry $sex</a></FONT></td>";
echo "</tr>";
} elseif (isset($_POST['submit'])) { 

$postuser = "{$_POST['username']}";
$country  = "{$_POST['country']}";
$postsex = "{$_POST['sex']}";

$query = "SELECT * FROM users WHERE country = '$country' AND sex ='$postsex'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);

$user = "{$row['id']}";
$userq = "{$row['username']}";
$mycountry = "{$row['country']}";
$sex = "{$row['sex']}";
$city = "{$row['city']}";


echo "<TABLE width=600 bgcolor=black border=1 align=center cellpadding=4 cellspacing=0>"; 
echo "<tr>"; 
    echo  "<td width='35%'><a style='text-decoration:none' href='http://localhost/profile/index.php?user=$user'><FONT FACE='ariel' SIZE='2'>$userq<p>";
echo "$city, $mycountry $sex</a></FONT></td>";
echo "</tr>";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.