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? Link to comment https://forums.phpfreaks.com/topic/71185-how-would-i-do-this/ 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."; } ?> Link to comment https://forums.phpfreaks.com/topic/71185-how-would-i-do-this/#findComment-358047 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"; } } Link to comment https://forums.phpfreaks.com/topic/71185-how-would-i-do-this/#findComment-358049 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 Link to comment https://forums.phpfreaks.com/topic/71185-how-would-i-do-this/#findComment-358052 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.