Jump to content

Login Script not working


radian

Recommended Posts

Hey,

 

Below is a login script that keeps returning the following error:

The following error(s) occured:
Array

 

The code is here:

 

process_login.php

<?php

include_once "functions.php";

connect();

if($_POST['submit']){

    $username = protect($_POST['username']);
    $password = $_POST['password'];

    $errors[] = array();

        if(!$username){
            $errors[] = "You did not supply a username!";
        }

        if(!$password){
            $errors[] = "You did not supply a password!";
        }

        if(count($errors) >= 1){
            echo "The following error(s) occured:<br>\n";
                foreach($errors AS $error){
                    echo $error . "<br>\n";
                }
    } else {

        $sql = "SELECT * FROM `users` WHERE `username`='".$username."'";
        $res = mysql_query($sql) or die(mysql_error());

        if(mysql_num_rows($res) == 0){
            echo "The username you supplied does not exist!";
        }else {
            $sql2 = "SELECT * FROM `users` WHERE `username`='".$username."' AND `password`='".md5($password)."'";
            $res2 = mysql_query($sql2) or die(mysql_error());

            if(mysql_num_rows($res2) == 0){
            echo "Username and password combination incorrect!";
            }else {
                $row = mysql_fetch_assoc($res2);
                setcookie('id',$row['id'],time()+86400);
                session_start();
                $_SESSION['uid'] = $row['id'];

                header("Location: register.php");
            }
        }

    }

}else {

    echo "You are accessing this page incorrectly!";
}

?> 

 

functions.php

<?php

function protect($string){
    $string = mysql_real_escape_string($string);
    $string = strip_tags($string);
    $string = addslashes($string);
    
    return $string;
}

function connect(){
    $con = mysql_connect("localhost", "root", "") or die(mysql_error());
    $db = mysql_select_db("forum", $con);
}


?> 

 

Any help is much appreciated.

 

Radian

Link to comment
https://forums.phpfreaks.com/topic/146486-login-script-not-working/
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.