Friday, 29 January 2016

Insert data Query in PHP / PHP Insert record code / Insert record Query in PHP

<?php
$hostname='localhost';
$username='root';
$password='';
$connect=mysql_connect($hostname,$username,$password);
mysql_select_db('learning');

if(isset($_POST['submit1']))
    {
        $admission_number=$_POST['admission_number'];
        $first_name=$_POST['first_name'];
        $last_name=$_POST['last_name'];
        $mobile1=$_POST['mobile1'];
   
    $data="insert into students (pid,admission_number,first_name,last_name,mobile1) values ('','$admission_number','$first_name','$last_name',$mobile1)";
    mysql_query($data);
   

    if($data==true)
     {
        echo "Inserted";
     }
    else
    {
       echo "Error";
     }

    }


?>

<form id="form1" name="form1" method="post">
  <table width="360" border="0" align="center" cellpadding="5" cellspacing="0">
    <tbody>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td width="169">Admission Number</td>
        <td width="171">
        <input type="text" name="admission_number" id="admission_number"></td>
      </tr>
      <tr>
        <td>First Name</td>
        <td><input type="text" name="first_name" id="first_name"></td>
      </tr>
      <tr>
        <td>Last Name</td>
        <td><input type="text" name="last_name" id="last_name"></td>
      </tr>
      <tr>
        <td>Mobile</td>
        <td><input name="mobile1"  type="text" id="mobile1"  maxlength="10"></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><input type="submit" name="submit1" id="submit1" value="Submit"></td>
      </tr>
    </tbody>
  </table>
</form>

No comments:

Post a Comment