The Street Way

Simple Registration page using php with SQL Database

Now see the registration page using php with SQL database connectivity, Last we have seen the how to make simple login page like this.

So here, we make registration page. We use following page

Registration.php

This page used to display form of registration and we add php code in this file. we can use another file for write php code. But here see the combine because you can see how to uses submit button and php code.
-----------------------------------------------------------------------------------------------------
<?php
error_reporting(0);
mysql_connect('localhost','root','') or die(mysql_error()); // Connection path of Sql server
mysql_select_db('register') or die(mysql_error()); // Select Database from the Sql Server
?>
<html>
<head>
<title>Registration Page</title>
</head>
<style>
#form {
    width:300px;
    text-align:center;
    height:auto;
    font-family:"Times New Roman", Times, serif;
    border:2px solid #666;
    border-radius:5px;
    margin-top:15%;
    margin-left:40%;
}
</style>
<body>
<?php

if(isset($_REQUEST['reg']))
{
    $fn=$_REQUEST['fname'];
    $ln=$_REQUEST['lname'];
    $bdate=$_REQUEST['bdate'];
    $email=$_REQUEST['email'];
    $user=$_REQUEST['user'];
    $pass=$_REQUEST['pass'];
    $tel=$_REQUEST['tel'];
    $adr=$_REQUEST['adres'];
    $ptc=$_REQUEST['postc'];
   
    // Query for insert data into user table
    $reg="insert into `users`(firstname,lastname,birthdate,email,username,password,telephone,address,postcode) values('$fn','$ln','$bdate','$email','$user','$pass','$tel','$adr','$ptc')";
    $exe=mysql_query($reg); // Execution of Query
    if($exe==true)
    {
    echo "<script>alert('Registration successfully')</script>";
    }
    else
    {
    echo "<script>alert(table not exit)</script>";
    }
}
?>
<div id="form">
  <form action="" method="post" >
    <center>
      <table>
      <font color="red">
       </font>
         <th colspan="2">Registration</th>
        <tr>
          <td>Firstname</td>
          <td><input type="text" name="fname" maxlength="30" placeholder="Enter Firstname"></td>
        </tr>
        <tr>
          <td> Lastname </td>
          <td><input type="text" name="lname" maxlength="50" placeholder="Enter Lastname "></td>
        </tr>
        <tr>
          <td>Birthdate</td>
          <td><input type="text" name="bdate" maxlength="30" placeholder="Enter Birthdate"></td>
        </tr>
        <tr>
          <td> Email </td>
          <td><input type="email" name="email" maxlength="50" placeholder="Enter Email"></td>
        </tr>
        <tr>
          <td>Username</td>
          <td><input type="text" name="user" maxlength="30" placeholder="Enter Username"></td>
        </tr>
        <tr>
          <td> Password </td>
          <td><input type="password" name="pass" maxlength="50" placeholder="Enter Password"></td>
        </tr>
        <tr>
          <td>Telephone</td>
          <td><input type="number" name="tel" maxlength="30" placeholder="Enter Telephone"></td>
        </tr>
        <tr>
          <td>Address</td>
          <td><textarea   name="adres" maxlength="100" placeholder="Enter Address" /></textarea></td>
        </tr>
        <tr>
          <td> Post Code </td>
          <td><input type="number" name="postc" maxlength="50" placeholder="Enter PostCode"></td>
        </tr>
        <tr>
          <th colspan="2"><input type="submit" name="reg" value="Registration"></th>
        </tr>
      </table>
    </center>
  </form>
</div>
</body>
</html>

------------------------------------------------------------------------------------------------
The above code easy to understand for registration SQL database connection, Insert Record in database.

You can download this code with database here...
DOWNLOAD.zip
If you like this, then share with your friends. And if you have query, contact-me and give comment.

0 comments:

Post a Comment