LiamProductions Posted September 29, 2007 Share Posted September 29, 2007 Hey. How do i check if $_POST['user'] is equal to any of the values in row username in my db? Any pointers or code snippets? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted September 29, 2007 Share Posted September 29, 2007 <?php $user = $_POST['user']; $query = "SELECT col FROM users WHERE user='$user'"; $result = mysql_query($query)or die(mysql_error()); if (mysql_num_rows($result) > 0){ echo "Found a match!"; } else { echo "No results found."; } ?> Quote Link to comment Share on other sites More sharing options...
marcus Posted September 29, 2007 Share Posted September 29, 2007 $user = mysql_real_escape_string($_POST['user']); $sql = "SELECT * FROM `table` WHERE `username` LIKE '%$user%'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ echo "No users with that username exist!\n"; }else { while($row = mysql_fetch_assoc($res)){ echo "<a href=\"/users.php?username=$row[username]\">$row[username]</a><br>\n"; } } Quote Link to comment Share on other sites More sharing options...
Barand Posted September 29, 2007 Share Posted September 29, 2007 But if the username entered is "fred" then ...LIKE '%$user%' will also pull "alfred", "frederick", "freddy", "freda" etc Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.