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.
- <?php
- mysql_connect("localhost","root","");
- mysql_select_db("connect");
- ?>
- <html>
- <style>
- Body
- {
- Background-color:cyan;
- }
- b
- {
- color:#F00;
- }
- </style>
- <form method="post" name="frm">
- <table width="355" border="1" cellspacing="3" cellpadding="3" align=”center”>
- <tr>
- <td width="161">Name</td>
- <td width="167">
- <input type="text" name="user"></td>
- </tr>
- <tr>
- <td>Password</td>
- <td><input type="password" name="pass"></td>
- </tr>
- <tr>
- <td>email</td>
- <td><input type="email" name="email"></td>
- </tr>
- <tr>
- <td colspan="2" align="center"><input type="submit" name="ins" value="insert">
- <input type="submit" name="del" value="delete">
- <input type="submit" name="updt" value="update">
- <input type="submit" name="dsp" value="display all">
- </td>
- </tr>
- </table>
- <?php
- $user=$_POST['user'];
- $pass=$_POST['pass'];
- $email=$_POST['email'];
- if($_POST['ins'])
- {
- $strQuery="insert into info(user,password,email) values('$user','$pass','$email')";
- $strResult = mysql_query($strQuery) or die("sanjay here is some error".mysql_error());
- echo "thnks for register <b>$user</b>";
- }
- if($_POST['del'])
- {
- $strQuery="delete from info where email='$email'";
- mysql_query($strQuery) or die("sanjay here is some error".mysql_error());
- echo "successfully deleted";
- }
- if($_POST['updt'])
- {
- $strQuery="update info set user='$user' where email='$email'";
- mysql_query($strQuery);
- echo "update successfully";
- }
- if($_POST['dsp'])
- {
- $strQuery="select * from info";
- $strResult=mysql_query($strQuery);
- $res=mysql_fetch_array($strResult);
- print_r ($res);
- }
- ?>
- </form>
- </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
![]()