954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

storing values in Textboxes in Register page

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>


<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>


<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:

</td>

<td align="left" width="50%" valign="top">

<input type="password" name="password" value= <?php $_POST[password]?>>

</td>


</tr>

<tr>

<td align="right" width="50%" valign="top">

Retype Password:

</td>

<td align="left" width="50%" valign="top">

<input type="password" name="repassword" >

<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><?php print ("Date, "); echo date("d:m:y", time());?></font></div>

</td>

</tr>

</table>

</div>

</body>

</html>
emarshah
Junior Poster in Training
61 posts since Jan 2008
Reputation Points: 10
Solved Threads: 6
 

Hi, could you explain more. I dont really get what you want?
Restore what ?

Thanks

Designer_101
Posting Whiz
314 posts since Jul 2007
Reputation Points: 12
Solved Threads: 16
 

I believe he wants to redisplay the values that the user entered if the form fails validation and needs to be edited and resubmitted.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

When you validate each feild set each one as a session. Something like this:

$_SESSION['name'] = $_POST['name'];


Therefore when the page validates you could do the following to each input.

<input type='text' name='name' value="
<?php 
if (isset ($_POST['name'] && !empty ($_POST['name'])) {
echo $_POST['name'];
}
 ?>
">


The code above wont work however it gives you an outline of how what you want can be done.
If you need help coding the system please say.

Hope this helps

Designer_101
Posting Whiz
314 posts since Jul 2007
Reputation Points: 12
Solved Threads: 16
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You