need help with this. so in index.php i have a html tag
<p id = 'login_error'></p>
here(p tag) i want to print all the errors which are tested in login.php.
in login.php i create a array called $error = array(); where has all the errors.
in error_message.php iam printing all the errors.
so some how i am trying to print all the errors in index.php which are tested in login.php.
here what iam thingking, in index.php
<p id = 'login_error'> include"error_message"</p>
full code.................
-------------------------------------------- index.php------------------------------------------------
<?php
session_start();
include("connect.php");
//check, if user is loged in or not
if(isset($_SESSION['username']))
{
//log in(member)
echo
"
YOU ARE LOGED IN
<a href='logout.php'> logout! </a>
";
}
else
{
//not loged in(not member)
echo
"
YOU ARE NOT LOG IN!
<form method='post' action='login.php'>
<strong>Member Login </strong><br/>
<p id = 'login_error'> </p>
Username:<input name='username' type='text' id='username'><br/>
Password: <input name='password' type='password' id='password'><br/>
<input type='submit' value='Login'>
<a href='register.php'> Register! </a>
</form>
";
}
?>
---------------------------------------------------login.php-------------------------------------------------------------
<?php
session_start();
include("connect.php");
$post_username = $_POST['username'];
$post_password = $_POST['password'];
if($post_username && $post_password)
{
$error = array();
if(strlen($post_username) == 0 || strlen($post_password) == 0)
{
$errror[] = "Username and password required!";
}
if(strlen($post_username) > 20 || strlen($post_password) > 20)
{
$errror[] = "Username or Password character length is too long!";
}
else
{
//convert password to md5
$port_password = md5($post_password);
//query the database /* table */
$login = sprintf("SELECT * FROM user WHERE username='%s' AND password ='%s'", mysql_real_escape_string($post_username),mysql_real_escape_string($post_password));
$rowcount = mysql_num_rows(mysql_query($login));
$fieldarray= mysql_fetch_assoc(mysql_query($login));
$id = $fieldarray['user_id'];
if($rowcount == 1)
{
//log the user in
$_SESSION['username'] = $post_username;
$_SESSION['user_id'] = $id;
header('Location: index.php');
}
else
$error[] = 'Incorrect username or password combination!';
}
}
header('Location: index.php');
//print all errors
foreach($error as $login_error)
{
echo "<p id = 'login_error'>$error</p>";
}
?>
--------------------------------------------------error_message.php------------------------------------
<?php
/* when a user login it give a vaiable. Its for testing if user login or logout*/
session_start();
include("connect.php");
//print all errors
foreach($error as $error)
{
echo "<p id = 'login_error'>$error</p>";
}
?>