gergy008 Posted August 18, 2009 Share Posted August 18, 2009 What query would I use that searches for a user in the database? This if statement is what asks for the function. It just tells the function what mode of look to use, And what to look for. The arrow states the line. if(lookup("lookforuser", $ID)==false){ <----------------------- echo("Can't find user in DB"); <-- This is for me, I don't need the user to see this. header("Location: users.php?mode=browse"); } I have this as the function also: function lookup($for, $arg) { global $link; if($for=="lookforuser"){ $sql="SELECT login FROM users WHERE login='".$arg."'"; $result=mysql_query($sql, $link); if($result){ return true; } else { return false; } } } As you can see, The SQL query is this: SELECT login FROM users WHERE login=$arg Is there any better than that? I just want it all to fit nicely so it checks if the user is in the DB and it returns true or false if the user is or isn't. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/170897-solved-what-sql-query-do-i-use-to-look-for-a-user/ Share on other sites More sharing options...
gergy008 Posted August 18, 2009 Author Share Posted August 18, 2009 Doesn't matter. I solved it by myself Here is the fixed-up function: function lookforuser($arg) { global $link; $query="SELECT login FROM users WHERE login='$arg'"; $result=mysql_query($query, $link) or die("MySQL query $query failed. Error if any: ".mysql_error()); $row=mysql_fetch_array($result); if($row){ return true; } else { return false; } } Link to comment https://forums.phpfreaks.com/topic/170897-solved-what-sql-query-do-i-use-to-look-for-a-user/#findComment-901393 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.