radian Posted February 23, 2009 Share Posted February 23, 2009 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 More sharing options...
PFMaBiSmAd Posted February 23, 2009 Share Posted February 23, 2009 This line - $errors[] = array(); Should be this - $errors = array(); Link to comment https://forums.phpfreaks.com/topic/146486-login-script-not-working/#findComment-769011 Share on other sites More sharing options...
radian Posted February 23, 2009 Author Share Posted February 23, 2009 excellent thanks Link to comment https://forums.phpfreaks.com/topic/146486-login-script-not-working/#findComment-769013 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.