BCA Practical 20

Practical 20 : Write a PHP Program for Add Record into Database
<html>

  <head>

  <title>Practical : 20</title>

  </head>

  <body>

  <?php 

  

  mysql_connect("localhost","root","");

  mysql_select_db("Class_DB");

  

  if(isset($_POST['insert']))

  {

  $sno=$_POST['sno'];

  $sname=$_POST['sname'];

  $sadd=$_POST['sadd'];

  

  $sql="Insert into Student values ('$sno','$sname','$sadd')"; 

  mysql_query($sql);

  $row=mysql_affected_rows();

  

  if($row==1)

  {

  $msg = "Record Inserted";

  }

  else

  {

  $msg = "Record Not Inserted";

  }

  

  }

  ?>
<center>

  <form name="f1" method="post">

  <table border="0px">

  <tr>

  <td>Sno. : </td>

  <td><input type="text" name="sno"></td>

  </tr>

  

  <tr>

  <td>Student Name : </td>

  <td><input type="text" name="sname"></td>

  </tr>
<tr>

  <td>Address : </td>

  <td>

  <textarea name="sadd" cols="15" rows="3"></textarea>

  </td>

  </tr>
<tr>

  <td colspan="2" align="center">

  <b><?php  echo $msg;?></b>

  </td>

  </tr>


<tr>

  <td colspan="2" align="center">

  <input type="submit" name="insert" value="Insert">

  <input type="reset" name="reset" value="Reset">

  </td>

  </tr>
</table>

  </center>
</form>

  </body>

  </html>


EmoticonEmoticon