Hi guys, I am new here and this is my first post
I have an issue with validating the login form, whereas if the fields are empty then it should display a message next to the respective field. The login is working perfectly but I am havin an issue with validating the fields.
here’s the php login code.
[php]<?php
session_start();
$username = $_POST[‘username’];
if(empty($username))
{ echo(“Please Input UserName”); }
$password = $_POST[‘password’];
if(empty($password))
{ echo(“Please Input Password”); }
if(isset($_POST[‘admin’]) && $_POST[‘admin’]==“admin”)
{
$type=“admin”;
}
else
{
$type=“normal”;
}
$con = mysql_connect(“localhost”,“root”,“alpine”) or die (“Couldn’t connect”);
if($type==“admin”)
{
mysql_select_db(“database_acc”, $con);
$result = mysql_query(“SELECT * FROM admin”);
while($row = mysql_fetch_array($result))
{ if($row[‘user_id’]==$username && $row[‘password’]==$password) {
$_SESSION[‘user’]=$username;
$_SESSION[‘type’]=“admin”;
$acc=$acc+1;
header( ‘Location: admin.php’);
}
}
}
else
{
mysql_select_db(“database_acc”, $con);
$result = mysql_query(“SELECT * FROM members”);
while($row = mysql_fetch_array($result))
{
if($row[‘email’]==$username && $row[‘password’]==$password)
{
$_SESSION[‘user’]=$username;
$_SESSION[‘type’]=“normal”;
$acc=$acc+1;
header( ‘Location: members.php’);
}
}
}
if($flag==0)
{ header( ‘Location: index.php?invalidlogindetails=1’);
$_SESSION[‘details’]=“1”; }
?> [/php]
here’s the form code…
[php]<?php
session_start();
if(!isset($_SESSION[‘user’]) ) {
?>
I am using the isset function that has a variable in it… and if possible to carry that forward with empty fields would be great.
Thanks guys. jay