Friday 16 August 2013

Step By Step Insert Record Using Php Mysql


Step By Step Insert Record Using Php Mysql

we can insert record using php, mysql. mysql is used to store the data and php is used to send the query to mysql database. this below example give the full details about how to insert record in mysql using php.



registration.php


<?php

echo $pass=rand();
$epass=md5($pass);
$con=mysql_connect("localhost","root","");
mysql_select_db('project',$con);

$sql="insert into registration(fname,lname,emailid,password,status,role)values('".$_POST['fnm']."','".$_POST['lnm']."','".$_POST['emailid']."','$epass','a','u')";
mysql_query($sql);

?>

<body>
<form method="post">
<table align="center" border="1">

<tr>
    <td>First Name</td>
    <td><input type="text" name="fnm" />
</tr>


<tr>
    <td>Last Name</td>
    <td><input type="text" name="lnm" />
</tr>

<tr>
    <td>EmailId</td>
    <td><input type="text" name="emailid" />
</tr>




<tr>
    <td><input type="submit" name="submit" value="Submit" /></td>
    <td><input type="reset" name="reset" /></td>
</tr>

</table>

</form>
</body>
</html>

database


















***********************************************************************
New Example




















Insert.php


<html>
<head>
<title>Untitled Document</title>
</head>

<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("demo");
echo $hb=$_POST['txtchk1']." ".$_POST['txtchk2']." ".$_POST['txtchk3'];

$sql="insert into stud(name,city,pincode,gender,hobby,branch,address)
values('".$_POST['fname']."','".$_POST['txtcity']."',".$_POST['pincode'].",'".$_POST['txtgen']."','".$hb."','".$_POST['txtbranch']."','".$_POST['txtadd']."')";
mysql_query($sql);
?>


<body>
<form method="post">
<table align="center" border="1">
    <tr>
   
        <td>First Name:</td>
        <td><input type="text" name="fname"></td>
    </tr>

<tr>

    <td>City:</td>
    <td><input type="text" name="txtcity"></td>

</tr>


<tr>
    <td>Pincode:</td>
    <td><input type="text" name="pincode"></td>

</tr>

<tr>

    <td>Gender:</td>
    <td>F:<input type="radio" name="txtgen" value="F">
   
        M:<input type="radio" name="txtgen" value="M">
    </td>

</tr>

<tr>
    <td>Hobby:</td>
    <td>
        Read:<input type="checkbox" name="txtchk1" value="Read">
        Playing:<input type="checkbox" name="txtchk2" value="Playing">
        Other:<input type="checkbox" name="txtchk3" value="Other">
    </td>

</tr>

<tr>
    <td>Branch:</td>
    <td>
        <select name="txtbranch">
        <option>BCA</option>
        <option>BIT</option>
        <option>PGDCA</option>
           
        </select>
   
    </td>

</tr>

<tr>
    <td>Address:</td>
    <td><textarea name="txtadd"></textarea> </td>

</tr>
<tr>
   
    <td><input type="submit" name="submit" value="Submit"></td>
    <td><input type="reset" name="reset" value="Cancle"></td>

</tr>
</table>

</form>
</body>
</html>







Share This
Previous Post
Next Post

3 comments:

  1. This code is so useful in my php Project so.. Thanxxx Mr. Pradip Vanparia

    ReplyDelete
  2. This code is useful in my Project

    ReplyDelete