Jump to content

check if exist


euel

Recommended Posts

Gud pm!!

So i made this script to check if a username and password exist but it kinda fails me.

It gives me a database connection error from my confirm_query() which means it returned false?

so here's my code:

 

  function check_if_exist($username, $password)
{
global $connection;
	$query = "SELECT username, hashed_password";
	$query .= "FROM users ";
	$query .= "WHERE username = '$username' ";
    $query .= "AND hashed_password = '$password' ";
	$query .= " LIMIT 1";
	$result_set = mysql_query($query, $connection);
	confirm_query($result_set);
	if(mysql_num_rows($result_set) == 1)
	{
	return true;
	}
	else
	{
	return false;
	}
}

 

my confirm_query():

 

function confirm_query($result)
{
if(!$result)
{
	die("Database connection failure ". mysql_error());
}
}

 

I have a another script to check if the email exist and it works perfectly, i dunno why this won't work properly..  :-\

maybe another simple mistake..

Any ideas or Violent reaction?  :D

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/255340-check-if-exist/
Share on other sites

Because I'm referring to my db $connection which is located somewhere else.. since it does not change.. making it global makes it available if needed it while not repeating my self over and over again..

 

Anyways back to my problem,

i think i do not need to that since it has mysql_error() already in it and it does report about an error on this line :

 

                $query .= "WHERE username = '$username' ";
        $query .= "AND hashed_password = '$password' ";
	$query .= " LIMIT 1";

 

the problem is i dunno what's wrong since like i have told from my 1st post that i have a same script for my email checking which works perfectly

and it's this:

 

function check_if_email_exist($email)
{
global $connection;
	$query = "SELECT email ";
	$query .= "FROM users ";
	$query .= "WHERE email = '$email' ";
	$query .= " LIMIT 1";
	$result_set = mysql_query($query, $connection);
	confirm_query($result_set);
	if(mysql_num_rows($result_set) == 1)
	{
	return true;
	}
	else
	{
	return false;
	}
}

Link to comment
https://forums.phpfreaks.com/topic/255340-check-if-exist/#findComment-1309151
Share on other sites

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.