Jump to content

Recommended Posts

Hi guys,

 

I made a login, and I have a function that is not working. I'll give you all of the parts to it.

 

Function:

 

 

}

function user_exists($username) {
$username = sanitize($username);
$query = mysql_query("SELECT COUNT (`id`) FROM `members` WHERE `username` = '$username'")
return (mysql_result($query, 0) == 1) ? true : false;
}

 

login page:

if(empty($_POST) === false) {
$username = $_POST['username'];
$password = $_POST['password'];



if(empty($username) === true || empty($password) === true) {
$errors[] = 'Please enter a username and password.';
}
else if(user_exists($username) === false) {
$errors[] = 'We can\'t find that username. Have you <a href="register.php">register</a>ed?';
}
else if(user_active($username) === false) {
$errors[] = 'You have not activated your account. Check your Email!';
} else {
$login = login($username, $password);
if($login === false) {
$errors[] = 'That username/password combination is incorrect.';
} else {
echo 'You are now logged in. Please wait for the page to refresh or click <a href="home.php">here</a>.';
$_SESSION['id'] = $login;
echo '<meta http-equiv="refresh" content="0;url=home.php">';
exit();
}
}

print_r($errors);
}
?>

 

Error: Fatal error: Call user_exists() in /home/a1922355/public_html/login.php on line 13

Edited by wickedXxxxlegox
Link to comment
https://forums.phpfreaks.com/topic/270418-login-function-problem/
Share on other sites

  On 11/7/2012 at 2:15 PM, Jessica said:

You have to include the file that has that function on your login page. Use require_once.

 

Oops, forgot to tell you that. I have the file included on init.php and then init.php is required on login,php.

Here's a readable version of your error (there's a remove format button, looks like an eraser) -

  On 11/7/2012 at 2:52 PM, wickedXxxxlegox said:

Dangit! Here: Fatal error: Call to undefined function user_exists in /home/a1922355/public_html/login.php on line 13

  On 11/7/2012 at 2:14 PM, wickedXxxxlegox said:

I'll give you all of the parts to it.

 

All the relevant parts would be ALL the code (less any database credentials), from the start of login.php up through the line where the error is occurring at. That would include (pun intended) your code showing how you are including the various files, along with showing the php tags in your file(s).

 

You either are including using a URL (doesn't include php code, only the output you send), don't have full php tags, or have multiple files at different paths, some with and some without that function definition in it.

You're missing a semi-colon in your user_exists() function.

 

function user_exists($username) {
$username = sanitize($username);
$query = mysql_query("SELECT COUNT (`id`) FROM `members` WHERE `username` = '$username'"); //<-- added semi-colon
return (mysql_result($query, 0) == 1) ? true : false;
}

 

Not sure if this fixes the error though.

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.