Hey All,
I have a Register.php page, whose code is as follows. On Register Me button, i want to restore values back in text boxes, when some invalid input is in textboxes. How can i do this?
<?php session_start(void); ?>
<html>
<head>
<title>Login System Using PHP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#6CADD0">
<div align="center">
<table width="800px" border="0">
<tr>
<td>
<div align="right"><font color="#FFFFFF" size="4" face="Verdana, Arial, Helvetica, sans-serif"><strong><hr color="#FFFFFF" align="right" width="30%">Login System Using Php<hr color="#FFFFFF" align="right" width="30%"></strong></font></div>
<br>
<font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong> <font color="#FFFFFF">Lab Task Definition :</font></strong>
<blockquote>
To create a full login system, including all type of input validation and use of mysql as database management system. The system should include registration and extras.
</blockquote>
</font>
<table width= "800px">
<tr>
<td width="100%" >
<Br>
<font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">
<strong>
<div align="center"><hr width="100%" color="#000000" size="1"><font color="#FFFFFF">Register Here</font><hr width="100%" color="#000000" size="1"></div>
</strong>
</font>
<br>
<div align="center">
<table width="600px" border="0">
<form action="register.php" method="post">
<tr>
<td align="right" width="50%" valign="top">
Username:
</td>
<td align="left" width="50%" valign="top">
<input type="text" name="username">
</td>
</tr>
<tr>
<td align="right" width="50%" valign="top">
Registration No:
</td>
<td align="left" width="50%" valign="top">
<input type="text" name="Regno">
</td>
</tr>
<tr>
<td align="right" width="50%" valign="top">
Password:<br>
</td>
<td align="left" width="50%" valign="top">
<input type="password" name="password" value= <?php $_POST[password]?>><br>
</td>
</tr>
<tr>
<td align="right" width="50%" valign="top">
Retype Password:<br>
</td>
<td align="left" width="50%" valign="top">
<input type="password" name="repassword" ><br><br>
<div align="center">
<input type="submit" value="Register Me">
</div>
</td>
<?php
if($_POST[username])
{
$Reg=$_POST[Regno];
$num1="^0[1-9]-[SCEMC]E-[0-9][1-9]$";
if(eregi($num1, $Reg))
{
$Pwd = $_POST[password];
$num2="^[1-9a-zA-Z]+$"; //password validation
$pwd1 = $_POST[repassword];
//echo $pwd1;
//echo $Pwd;
if (eregi($pwd1, $Pwd))
{
if(eregi($num2, $Pwd))
{
$conn = mysql_connect("localhost", "root", "");
mysql_select_db(logindb,$conn);
$sql = "SELECT * FROM student where registrationNo='$_POST[Regno]'";
$result = mysql_query($sql, $conn);
$row = mysql_fetch_array($result);
$reg=$row['RegistrationNo'];
if($reg!=$_POST[Regno])
{
$sql = "INSERT INTO users (username,registrationNo,password) values('$_POST[username]','$_POST[Regno]','$_POST[password]')";
mysql_query($sql, $conn);
header("location:index.php");
}
else
{
echo"<font color='#D0D0D0' size='2' face='Verdana'> <strong>You are already Registered..</strong></font> ";
}
}
else
{
echo"<font color='#D0D0D0' size='2' face='Verdana'> <strong>Please enter valid password.</strong></font> ";
}
}
else
{
echo"<font color='#D0D0D0' size='2' face='Verdana'><strong>Passwords don't match.</strong></font>";
}
}
else
echo"<font color='#D0D0D0' size='2' face='Verdana'><strong> Please enter valid reg No.</strong></font>";
}
else
{
echo"<font color='#000000' size='2' face='Verdana'><strong> Please enter your name </strong></font>";
}
?>
</tr>
</form>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="baseline">
<div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><strong>Developed By: Syed Ammar Hassan</strong><br><?php print ("Date, "); echo date("d:m:y", time());?></font></div>
</td>
</tr>
</table>
</div>
</body>
</html>