Create Simple Sign Up Form in PHP

Introduction

In this article I will describe how to design a simple sign up form for PHP. So in this article I will create two different applications, one for HTML design to provide the user view for sign up and the second one, that interacts with a MySQL database to save those values filled in by the new user. Now first I show you the simple design "sign up" form image.

registration-fron-inphp.gif

In order to create a user account, we need to gather a minimal amount of information from the user, we need his name, his password, maybe email id (if desired). So in the given image I use a name (textbox)  password (textbox), gender( Radio button) and keep signed up (check box) fields.

The following is the registration form design code:

<html>
<
body>
<
form action="login.php" method="post">
<
fieldset>
<
legend><h1>Sign Up Form</h1></legend>
<
div style="background:#00FF33;>
<
label for="name"><b>Name</b></label><br />
<
input name="name"  id="name" style="background-color:White; color:#0033CC; type="text" /><br />
<
label for="password"><b>Password</b></label><br />
<
input name="password" id="password"
type
="password" /><br /><br />
<
label>
<
input type="radio" name="gender" value="male"/>
Male

</
label><br />
<
label>
<
input type="radio" name="gender" value="female"/>
Female

</
label><br /><br />
<
input type="submit" value="Submit" /><br />
<
label>
 

<
input type="checkbox" name="notify">Keep me signed in on this computer</label><br />
</
div>
</
fieldset>
</
form>
</
body>
</
html>

So we have a text field for name, password, radio button for gender and a checkbox for keeping signed in. When you have filled in all values of the sign up form, it simply interacts with "login.php" using
<form action="login.php" method="post">.The login.php is basically created to interact with the MySQL database to save those values that are filled in by the user.

value-fill-in-registration-form.gif

The following is the login page code:

<?
php
$
con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("
mysql", $con);
$
sql="INSERT INTO mcn (name , pwd, gender) VALUES ('$_POST[name]','$_POST[password]','$_POST[gender]')";
if
(!mysql_query($sql,$con))
  {
 
die('Error: ' . mysql_error());
  }

echo
"Successfully Registered.";
print
"<h1>Retrive data</h1>";
$
result = mysql_query("SELECT * FROM mcn");
echo "<
table border='1'>
<
tr>
<
th>Name</th>
<
th>Password</th>
<
th>Gender</th>
</
tr>";
while($rowval = mysql_fetch_array($result))
{
echo "
<tr>";
echo "
<td>" . $rowval['name'] . "</td>";
echo "
<td>" . $rowval['pwd'] . "</td>";
echo "
<td>" . $rowval['gender'] . "</td>";
echo "
</tr>";
}
echo "
</table>";
mysql_close($con);

?>


Output

after-value-fill.gif


Similar Articles