contra10 Posted December 14, 2008 Share Posted December 14, 2008 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 More sharing options...
contra10 Posted December 14, 2008 Author Share Posted December 14, 2008 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>"; } Link to comment https://forums.phpfreaks.com/topic/136904-searching-sql-from-a-form/#findComment-715016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.