ok so I am trying to create a login page for my website, however after following a tutorial on creating all the functions and calls and everything I need to in order to get it up, I upload it to my server and when I try to test it the pages throw errors that make no sence, like it is currently throwing an error saying that my function "user_exists" is undefined, when I know it is there and defined as well as called correctly, My code follows.
the login page:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<center><h1><font color="#09729f">Rise & Shine<br/>Login</font></h1>
<form action="core/login.php" method="post">
User Name: <input type="text" name="userName" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" value="Login" />
</form></center>
</body>
</html>

The login.php:

<?php
include 'core/init.php';

if(empty($_POST) == false)
{
    $userName = $_POST['userName'];
    $password = $_POST['password'];
    if(empty($userName) == true || 
    empty($password) == true)
    {
        $errors[] = 'you need to enter a user name and password';
    }else if(user_exists($userName) == false)
    {
        $errors[] = 'can\'t find username';
    }else
    {
        $login = login ($userName, $password);
        if($login == false)
        {
            $errors[] = 'that username/password combination is incorrect';
        }else
        {
            //set session
            $_SESSION['user_id'] = $login;
            //redirect user
            header('Location:announcementEdit.php');
            exit();
        }
    }
    print_r($errors);
}
?>

The init.php:

<?php
session_start;
//error_reporting(0);

require 'database/conection.php';
require 'functions/users.php';
require 'functions/general.php';

$errors = array();
?>

Connection.php is the file I reference to connect to my database and just has my login information.
Here is the users.php:

<?php
function user_exists($userName)
{
    $userName = sanitize($userName);
    $query = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `userName` = '$userName'");
    return(mysql_result($query,0) == 1) ? true : false;
}

function user_id_from_userName($userName)
{
    $userName = sanitize($userName);

    return(mysql_result(mysql_query("SELECT `user_id` FROM `users` WHERE `userName` = '$userName'"), 0, 'user_id'));
}

function login($userName, $password)
{
    $user_id = user_id_from_userName($userName);
    $userName = sanitize($userName);
    $password = SHA1($password);

    return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE userName = '$userName' AND `password` = '$password'"), 0) = 1) ? $user_id : false;
}
?>

and last but not least, my general.php:

<?php
function sanitize($data)
{
    return mysql_real_escape_string ($data);
}
?>

so there is all my code, I am starting to think that perhaps It may be because I am not running mysql 5.5 yet, my boss refuses to upgrade the server right now so im workin with like 3 or something like that. please tell me whats wrong

ok so we are using version 5.1

Try putting those two lines at the begining of the page and see if throws any other errors:

error_reporting(E_ALL);
ini_set('display_errors', 1);

You could also try using function_exists to check if the function is defined.

Thanks, I will try that first thing in the morning.

thanks we found the problem it was a simple syntax error that I wasnt seeing, but yay mu boss found it for me facepalm

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.