infolink

Sunday 25 March 2012

PHP Form Tutorial ( Stored Client Information in Database)

This tutorial is about the PHP with MySQL Database. In this tutorial you learn how to insert/save the PHP form data into Database.
For this tutorial  follow these simply 4 steps :

--------------------------------------------------------------------------

Step 1:

create the Database with the name "clientinformation" and then create the table in this database. The table name is "client_reg". Like this:

CREATE TABLE IF NOT EXISTS `client_reg` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `ClientName` varchar(25) NOT NULL,
  `Address` varchar(50) NOT NULL,
  `CNICNumber` varchar(25) NOT NULL,
  `MobileNumber` varchar(25) NOT NULL,
  `TelephoneNumber` varchar(25) NOT NULL,
  `CompanyName` varchar(25) NOT NULL,
  `ClientStatus` tinyint(1) NOT NULL,
  `RegisterDate` date NOT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `CNICNumber` (`CNICNumber`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;

--------------------------------------------------------------------------

Step 2:

Now in this step design a form using HTML. Make a PHP page with name "ClientInfo.php". and design the form. Like this:

<table width="700" border="1">
<form id="form1" name="form1" method="post" action="ClientInfo.php?process">

  <tr>
    <td>Client Name </td>
    <td><label>
      <input name="ClientName" type="text" id="ClientName" />
    </label></td>
  </tr>
  <tr>
    <td>Address</td>
    <td>
      <label>
        <input name="Address" type="text" id="Address" />
        </label>
        </td>
  </tr>
  <tr>
    <td>CNIC No </td>
    <td>
      <label>
        <input name="CNICno" type="text" id="CNICno" />
        </label>
        </td>
  </tr>
  <tr>
    <td>Mobile Number </td>
    <td>
      <label>
      <input name="Mobileno" type="text" id="Mobileno" />
      </label>
        </td>
  </tr>
  <tr>
    <td>Telephone Number </td>
    <td>
      <label>
        <input name="Telephoneno" type="text" id="Telephoneno" />
        </label>
       </td>
  </tr>
  <tr>
    <td>Company Name </td>
    <td>
      <label>
        <input name="Companyname" type="text" id="Companyname" />
        </label>
        </td>
  </tr>
  <tr>
    <td>Client Status </td>
    <td>
 
 <p>
   <label>
     <input type="radio" name="Clientstatus" value="1" />
     Active</label>
   <br />
   <label>
     <input type="radio" name="Clientstatus" value="0" />
     Inactive</label>
   </p>
 
      </td>
  </tr>
  <tr>
    <td>Registered Date </td>
    <td>
      <label>
        <input name="RegisteredDate" type="text" id="RegisteredDate" />
        </label>
       </td>
  </tr>
  <tr>
    <td>
      <label>
      <input type="submit" name="Submit" value="Submit" />
        </label>
    </form>    </td>
  </tr>
</table>

the Output of the form is look like this:

HTML Form Client Info
Client Info Form

--------------------------------------------------------------------------

Step 3:

In the step 3 write the PHP code to make the connection with Database. The code is here:

<?php
$link=mysql_connect("localhost","root","");
  $database='clientinformation';              // it is Database name that you created
  if (!$link)
  die('Failed to connect to Server'.mysql_error());
  $db=mysql_select_db($database, $link);
  session_start();
  if(!$db)
  die('Failed to select Data Base '.mysql_error());
?>

--------------------------------------------------------------------------

Step 4:

Now its time to write the PHP code for insert the Data from the form to Database. Here write the insert query for the insertion.
Note:  write the following code at top of the "ClientInfo.php" page that was created in step 2.

if(isset($_GET['process']))
{
$query = "Insert INTO `client_reg` (ClientName, Address, CNICNumber, MobileNumber, TelephoneNumber, CompanyName, ClientStatus, RegisterDate) values('$_POST[ClientName]', '$_POST[Address]','$_POST[CNICno]','$_POST[Mobileno]', '$_POST[Telephoneno]', '$_POST[Companyname]', '$_POST[Clientstatus]', '$_POST[RegisteredDate]')";
//echo $query; exit;
$result = mysql_query($query) or die(mysql_error());
if(!$result)
{
$msg = "not Inserted";
}
else
{
$msg = "Inserted";
header("location:ClientList.php?m=".$msg);
}
}

?>

19 comments:

  1. wao its nice.

    nd wht about my tutorial

    waqasuow.hostzi.com/project1

    kindly leav a cmnt for me

    ReplyDelete
    Replies
    1. your site not running

      Delete
    2. waqasuow.hostzi.com/project1.htm


      sorry bro that link was nt wrking due to extnsn of the papge.

      hope so it will work now

      Delete
  2. Thank youuuuuuuuuuuuuuuu very much friend..
    i'm looking for a tutorial like this..
    it was really helpful...
    thank you so much...:)

    ReplyDelete
  3. NOT WORKING..............ERROR......WE CAN'T BE SUBMIT DATA

    ReplyDelete
  4. Where I insert the connection code On Top of what? and the send connection where?

    ReplyDelete
  5. Note: write the following code at top of the "ClientInfo.php" page that was created in step 2.

    So the statement Start in: if< and finish in ?>?

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. I wrote "require_once('connection.php');" after the <?.Then u insert the code in step 4. It worked for me! Thank u author!!

      Delete
  6. [quote]header("location:ClientList.php?m=".$msg);[/quote]

    Where's that ClientList.php went???

    ReplyDelete
  7. Thank you very much for the tips. I

    Website Development company

    ReplyDelete
  8. i have learn mvc please help me

    ReplyDelete
  9. how to insert and select and delete and update data

    ReplyDelete
  10. I truly liked looking over this submit, I ended up being just wanting to know would you trade included blogs. Thanks pertaining to expressing your website with other folks. You really share precious information.Nimble Social CRM

    ReplyDelete
  11. In the particular article You might understand how for getting started building net applications Android Applications Development

    ReplyDelete
  12. The share your really gives us excitement. Thanks for your sharing. If you feel tired at work or study try to participate in our games to bring the most exciting feeling. Thank you!
    swords sand souls | ninjago games | hola launcher | agario game | cooking fever | goodgame big farm | red ball 4 | agario | subway surfers | paradise bay | strike force kitty 2

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. This is very good information of PHP Application. Software Company in Dehradun

    ReplyDelete
  15. Thanks for sharing information...

    ReplyDelete