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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.