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 :
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:
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);
}
}
?>
wao its nice.
ReplyDeletend wht about my tutorial
waqasuow.hostzi.com/project1
kindly leav a cmnt for me
your site not running
Deletewaqasuow.hostzi.com/project1.htm
Deletesorry bro that link was nt wrking due to extnsn of the papge.
hope so it will work now
Thank youuuuuuuuuuuuuuuu very much friend..
ReplyDeletei'm looking for a tutorial like this..
it was really helpful...
thank you so much...:)
NOT WORKING..............ERROR......WE CAN'T BE SUBMIT DATA
ReplyDeleteWhere I insert the connection code On Top of what? and the send connection where?
ReplyDeleteNote: write the following code at top of the "ClientInfo.php" page that was created in step 2.
ReplyDeleteSo the statement Start in: if< and finish in ?>?
This comment has been removed by the author.
DeleteI wrote "require_once('connection.php');" after the <?.Then u insert the code in step 4. It worked for me! Thank u author!!
Delete[quote]header("location:ClientList.php?m=".$msg);[/quote]
ReplyDeleteWhere's that ClientList.php went???
Thank you very much for the tips. I
ReplyDeleteWebsite Development company
i have learn mvc please help me
ReplyDeletehow to insert and select and delete and update data
ReplyDeleteI 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
ReplyDeleteIn the particular article You might understand how for getting started building net applications Android Applications Development
ReplyDeleteThe 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!
ReplyDeleteswords 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
This comment has been removed by the author.
ReplyDeleteThis is very good information of PHP Application. Software Company in Dehradun
ReplyDeleteThanks for sharing information...
ReplyDelete