hi m making aregisteration form for employees. n validate its some very basic field. but the problem is
that if i enter wrong it shows me the error and says click here to refill as told by me

but when i enter the correct data even then it shows click here to refill the form instead of saying that it is succesfuly saved. my code for geting data is

<?php
 
 
session_start();	
 
 //Array to store validation errors
  $errorMsgArray = array();
 
  //Validation error flag
  $errorFlag = false;
 
 
 $con=mysql_connect("localhost","root","");
 
	mysql_select_db("pras2");
 
 
function mysql_fix_string($string)
{	
	if (get_magic_quotes_gpc()) 
	$string = stripslashes($string);
	return mysql_real_escape_string($string);
}
 
 
 
$name=$_POST['name'];
$username=$_POST['username'];
$password=$_POST['password'];
$rep_password=$_POST['rep_password'];
$adress=$_POST['address'];
$num=$_POST['num'];
$rank=$_POST['rank'];
$department=$_POST['department'];
$dateOfJoining=$_POST['doj'];
$dateOfBirth=$_POST['dob'];
$qualification=$_POST['qualification'];
$NIC=$_POST['nic'];


$_SESSION['name'] = $name;
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
$_SESSION['rep_password'] = $rep_password;
$_SESSION['adress'] = $adress;
$_SESSION['num'] = $num;
$_SESSION['rank'] = $rank;
$_SESSION['department'] = $department;
$_SESSION['dateOfJoining'] = $dateOfJoining;
$_SESSION['dateOfBirth'] = $dateOfBirth;
$_SESSION['qualification'] = $qualification;
$_SESSION['NIC'] = $NIC;


if ($name=="" || $username="" || $password="" || $adress="" || $num=""|| $rank="" || $department="" || $dateOfJoining="" || $dateOfBirth="" ||$qualification="" || $NIC="" )
{
$errorMsgArray[]="something is missing";
$errorFlag=true;
}

 
if (strcmp($password, $rep_password)!=0)
{
$errorMsgArray[]="both passwords donot match";
$errorFlag=true;
}
 

 
//If there are input validations, redirect back to the registration form
  if($errorFlag) {
    $_SESSION['ERROR_MSG_ARRAY'] = $errorMsgArray;
	session_write_close();
    header("location: errors.php");
    exit();
  }
 
 
$query = "INSERT INTO employee (employee_id, password, employee_name, rank, department_id, nic, d_o_birth, d_o_joining, phone_num, address, qualification) VALUES ('$username' , '$password','$name' , '$rank', '$department', '$NIC', '$dateOfBirth', '$dateOfJoining' , '$num', '$adress' , '$qualification')";
 
$result=mysql_query($query);
if (!$result) die ("Database access failed: " . mysql_error());
 
else
{
echo "Your record has been successfully added <br> <br>";
echo "<a href=\"employee_registeration.php\"> Click to add another record</a>";
}
mysql_close($con);
 
 
 
?>

my code for showing errors are:

errors.php

<?php

session_start();

 
$name  =  $_SESSION['name'];	
$username =  $_SESSION['username']; 	
$password =  $_SESSION['password']; 	
$rep_password = $_SESSION['rep_password']; 	
$adress = $_SESSION['adress'];		
$department =  $_SESSION['department'];			
$rank =  $_SESSION['rank'];
$dateOfJoining =  $_SESSION['dateOfJoining'];			
$dateOfBirth =  $_SESSION['dateOfBirth'];			
$qualification =  $_SESSION['qualification'];			
$NIC =  $_SESSION['NIC'];			
$num= $_SESSION['num'];		

 
if ($name=="")
{
echo "Name is missing<br/>";
}
 
if ($username=="")
{
echo"Username is mising<br/>";
 
}
 
if ($password=="")
{
echo "U havenot entered password<br/>";
}
 
if ($rep_password=="")
{
echo "Please enter ur password again<br/>";
}
 
if ($num=="")
{
echo "Please enter your number<br/>";
}
 

if($adress=="")
{
echo "Please enter your address<br/>";
}

if($dateOfBirth=="")
{
echo "Please enter your dateof birth<br/>";
}

if($dateOfJoining=="")
{
echo "Please enter your date of joining<br/>";
}

if($rank=="")
{
echo "Please enter your rank<br/>";
}

if($department=="")
{
echo "Please enter your department<br/>";
}

if($NIC=="")
{
echo "Please enter your NIC<br/>";
}
 
if (strcmp($password, $rep_password)!=0)
{
echo "Both passwords donot match<br/>";
 
}


echo "<a href=\"employee_registeration.php\"> Click here to re-enter the record</a>";
session_destroy();

?>

It seems ok but I don't see the form, so check if there is something different between field names and $_POST vars. Bye :)

found the problem.it lies on line55 of first file. there should be "==" instead of "=" :-)

commented: good and thank you for sharing ;D +7
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.