Insert , Delete, Update and display Using PHP

We all know PHP is a server side scripting language which is basically used to make dynamic web pages or websites. It support many databases but the best compatibility of PHP is with mySql.

  1. <?php  
  2. mysql_connect("localhost","root","");  
  3. mysql_select_db("connect");  
  4. ?>  
  5. <html>  
  6. <style>  
  7. Body  
  8. {  
  9. Background-color:cyan;  
  10. }  
  11. b  
  12. {  
  13.     color:#F00;  
  14. }  
  15. </style>  
  16. <form method="post" name="frm">  
  17. <table width="355" border="1" cellspacing="3" cellpadding="3" align=”center”>  
  18.   <tr>  
  19.     <td width="161">Name</td>  
  20.     <td width="167">  
  21.     <input type="text" name="user"></td>  
  22.   </tr>  
  23.   <tr>  
  24.     <td>Password</td>  
  25.     <td><input type="password" name="pass"></td>  
  26.   </tr>  
  27.   <tr>  
  28.     <td>email</td>  
  29.     <td><input type="email" name="email"></td>  
  30.   </tr>  
  31.   <tr>  
  32.     <td colspan="2" align="center"><input type="submit" name="ins" value="insert">  
  33.     <input type="submit" name="del" value="delete">  
  34.     <input type="submit" name="updt" value="update">  
  35.     <input type="submit" name="dsp" value="display all">  
  36.     </td>  
  37.   </tr>  
  38. </table>  
  39. <?php  
  40. $user=$_POST['user'];  
  41. $pass=$_POST['pass'];  
  42. $email=$_POST['email'];  
  43. if($_POST['ins'])  
  44. {  
  45.     $strQuery="insert into info(user,password,email) values('$user','$pass','$email')";  
  46.     $strResult = mysql_query($strQueryor die("sanjay here is some error".mysql_error());  
  47.     echo "thnks for register <b>$user</b>";  
  48. }  
  49. if($_POST['del'])  
  50. {  
  51.     $strQuery="delete from info where email='$email'";  
  52.     mysql_query($strQueryor die("sanjay here is some error".mysql_error());  
  53.     echo "successfully deleted";  
  54. }  
  55. if($_POST['updt'])  
  56. {  
  57.     $strQuery="update info set user='$user' where email='$email'";  
  58.     mysql_query($strQuery);  
  59.     echo "update successfully";  
  60. }  
  61. if($_POST['dsp'])  
  62. {  
  63.     $strQuery="select * from info";  
  64.     $strResult=mysql_query($strQuery);  
  65.     $res=mysql_fetch_array($strResult);  
  66.     print_r ($res);  
  67. }  
  68. ?>  
  69. </form>  
  70. </html>  
Output



And the database is look like



Insert the value in the input boxes



Now we click on insert



Now if we want to update the entry from sanjay singh to sanjay



And now click on update button

Then the output is



Now if we want to display all the item on front page then(



Now just click on display all button-

The output is



Now we delete the input



And just click on delete button

Output is




Ebook Download
View all
Learn
View all