Jump to content

[SOLVED] What SQL query do I use to look for a user?


gergy008

Recommended Posts

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.

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;
}
}

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.