Android Tutorial , Programming Tutorial, Php Tutorial, Learn Android, HTML Tutorial, Coding , Java Tutorial, GTU Programs, Learning Programming

Sunday 18 September 2016

Insert , Update , Delete in mysql using php

In this example, CRUD operation (Insert,update,delete,view Record) is describe here. As we enter data in textbox , that data will be stored in the database which is created in mysql. We can update record. If record is available in the database table then we can update otherwise we can't update record. We can delete record by adding first name in this example. To make attractive look of form, in this example materialize css is used in the example .Let's see the example :

File Name :- insert.php

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
 $servername= "localhost";
 $username = "root";
 $password="";
 $dbname="dbmultiple";
 
 $conn = new mysqli($servername,$username,$password,$dbname);
 if($conn->connect_error)
 {
  die("Connection Failed".$conn->connect_error);
 }
 if(isset($_POST['cancel']))
 {
  $fn = $_POST["fname"];
  $ln = $_POST["lname"];
  $fn="";
  $ln="";
 }
 if(isset($_POST['insert']))
 {
  $fn = $_POST["fname"];
  $ln = $_POST["lname"];  
  $sql = "INSERT INTO users(first_name,last_name) VALUES ('".$fn."','".$ln."')";
  if($conn->query($sql)===TRUE)
  {
   echo "Record Insert Successfully";
  }
  else
  {
   echo "Error :".$sql."<br>".$conn->error;
  }
 }
 $conn->close();
?>
<html>
<head>
<link rel="stylesheet" href="css/materialize.css"/>
<link rel="stylesheet" href="css/materialize.min.css"/>
</head>
<body>
<center>
<form method="POST" >
<div class="row">
 <div class="input-field col s6">
  
  <input type="text" name="fname" placeholder="Enter First Name" required><br/>
  <input type="text" name="lname" placeholder="Enter Last Name" required><br/>


 <input type="submit" name="insert" value="Insert" class="waves-effect waves-light btn">
 <input type="submit" name="cancel" value="Cancel" class="waves-effect waves-light btn">

</div>
</form>
</center>
<script type="text/javascript" src="js/materialize.js"/>
<script type="text/javascript" src="js/materialize.min.js"/>

</body>

</html>

Output :



File Name : update.php



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
 $servername= "localhost";
 $username = "root";
 $password="";
 $dbname="dbmultiple";
 
 $conn = new mysqli($servername,$username,$password,$dbname);
 if($conn->connect_error)
 {
  die("Connection Failed".$conn->connect_error);
 }
 if(isset($_POST['cancel']))
 {
  $fn = $_POST["fname"];
  $ln = $_POST["lname"];
  $fn="";
  $ln="";
 }
 if(isset($_POST['update']))
 {
  $fn = $_POST["fname"];
  $ln = $_POST["lname"];  
  $sql = "UPDATE users SET last_name='$ln' WHERE first_name='$fn'";
  if($conn->query($sql)===TRUE)
  {
   echo "Record UPDATE Successfully";
  }
  else
  {
   echo "Error :".$sql."<br>".$conn->error;
  }
 }
 $conn->close();
?>
<html>
<head>
<link rel="stylesheet" href="css/materialize.css"/>
<link rel="stylesheet" href="css/materialize.min.css"/>
</head>
<body>
<center>
<form method="POST" >
<div class="row">
 <div class="input-field col s6">
  
  <input type="text" name="fname" placeholder="Enter First Name" required><br/>
  <input type="text" name="lname" placeholder="Enter Last Name" required><br/>


 <input type="submit" name="update" value="Update" class="waves-effect waves-light btn">
 <input type="submit" name="cancel" value="Cancel" class="waves-effect waves-light btn">

</div>
</form>
</center>
<script type="text/javascript" src="js/materialize.js"/>
<script type="text/javascript" src="js/materialize.min.js"/>
</body>
</html>
Output :


File Name : delete.php


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
 $servername= "localhost";
 $username = "root";
 $password="";
 $dbname="dbmultiple";
 
 $conn = new mysqli($servername,$username,$password,$dbname);
 if($conn->connect_error)
 {
  die("Connection Failed".$conn->connect_error);
 }
 if(isset($_POST['cancel']))
 {
  $fn = $_POST["fname"];
  $ln = $_POST["lname"];
  $fn="";
  $ln="";
 }
 if(isset($_POST['delete']))
 {
  $fn = $_POST["fname"];
  $sql = "DELETE FROM users WHERE first_name='$fn'";
  if($conn->query($sql)===TRUE)
  {
   echo "Record DELETE Successfully";
  }
  else
  {
   echo "Error :".$sql."<br>".$conn->error;
  }
 }
 $conn->close();
?>
<html>
<head>
<link rel="stylesheet" href="css/materialize.css"/>
<link rel="stylesheet" href="css/materialize.min.css"/>
</head>
<body>
<center>
<form method="POST" >
<div class="row">
 <div class="input-field col s6">
  
 <input type="text" name="fname" placeholder="Enter First Name" required><br/>
 
 <input type="submit" name="delete" value="Delete" class="waves-effect waves-light btn">
 <input type="submit" name="cancel" value="Cancel" class="waves-effect waves-light btn">

</div>
</form>
</center>
<script type="text/javascript" src="js/materialize.js"/>
<script type="text/javascript" src="js/materialize.min.js"/>
</body>
Output :


Note :

Database Name : dbmultiple
Table Name : users
Field Name : first_name,last_name

CSS Download link : Click Here

  30 comments:

  1. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
    Regards,
    PHP Institutes in Chennai|PHP Training Center in Chennai

    ReplyDelete

  2. I wish to show thanks to you just for bailing me out of this particular trouble.As a result of checking through the net and meeting techniques that were not productive, I thought my life was done.
    Advanced Selenium Training in Chennai

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Your new valuable key points imply much a person like me and extremely more to my office workers. With thanks; from every one of us.
    AWS Online Training

    ReplyDelete
  6. I am a regular reader of your blog and being students it is great to read that your responsibilities have not prevented you from continuing your study and other activities. Love
    Click here:
    angularjs training in velarchery
    Click here:
    angularjs training in sholinganallur

    ReplyDelete
  7. I was looking for this certain information for a long time. Thank you and good luck.
    Click here:
    Microsoft azure training in bangalore
    Click here:
    Microsoft azure training in pune

    ReplyDelete
  8. I am really happy with your blog because your article is very unique and powerful for new reader.
    Click here:
    Selenium Training in Chennai | Selenium Training in Bangalore | Selenium Training in Pune | Selenium Training in Chennai

    ReplyDelete
  9. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.

    best rpa training in chennai |
    rpa training in chennai |
    rpa training in bangalore
    rpa training in pune | rpa online training

    ReplyDelete
  10. Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.
    Data Science training in Chennai | Data science training in bangalore
    Data science training in pune | Data science online training
    Data Science Interview questions and answers | Python training in Kalyan nagar

    ReplyDelete
  11. Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
    angularjs online Training

    angularjs Training in marathahalli

    angularjs interview questions and answers

    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs online Training

    ReplyDelete
  12. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information. 
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training

    ReplyDelete
  13. After reading your post I understood that last week was with full of surprises and happiness for you. Congratz! Even though the website is work related, you can update small events in your life and share your happiness with us too.
    python Training in Pune
    python Training in Chennai
    python Training in Bangalore

    ReplyDelete
  14. Really you have done great job,There are may person searching about that now they will find enough resources by your post
    Microsoft Azure online training
    Selenium online training
    Java online training
    Python online training
    uipath online training

    ReplyDelete
  15. Hi,
    Good job & thank you very much for the new information, i learned something new. Very well written. It was sooo good to read and usefull to improve knowledge. Who want to learn this information most helpful. One who wanted to learn this technology IT employees will always suggest you take python training in bangalore. Because Python course in Bangalore is one of the best that one can do while choosing the course.

    ReplyDelete
  16. Get enrolled for the most demanding skill on the Data Science Training in Hyderabad will make your career a new height. We at Analytics Path provide you with an excellent stage to learn and explore the subject from industry experts. We help students to dream high and achieve it.
    For More Info Data Science Training In Hyderabad

    ReplyDelete
  17. Great blog created by you. I read your blog, its best and useful information. Super blogging and keep it updating
    Blockchain Training in Hyderabad

    ReplyDelete
  18. Big Thanks for this wonderful read. I enjoyed every little bit of reading and I have bookmarked your website to check out new stuff of your blog a must read blog.good luck.
    Ai & Artificial Intelligence Course in Chennai
    PHP Training in Chennai
    Ethical Hacking Course in Chennai Blue Prism Training in Chennai
    UiPath Training in Chennai

    ReplyDelete
  19. I just recently discovered your blog and have now scrolled through the entire thing several times. I am very impressed and inspired by your skill and creativity, and your "style" is very much in line with mine. I hope you keep blogging and sharing your design idea

    data science training in chennai

    data science training in velachery

    android training in chennai

    android training in velachery

    devops training in chennai

    devops training in velachery

    artificial intelligence training in chennai

    artificial intelligence training in velachery


    ReplyDelete
  20. Awesome blog it's very nice and useful i got many more information it's really nice i like your blog

    AI Training in Hyderabad

    ReplyDelete
  21. ExcelR provides data scientist course in pune . It is a great platform for those who want to learn and become a data scientist. Students are tutored by professionals who have a degree in a particular topic. It is a great opportunity to learn and grow.

    data scientist course in pune


    ReplyDelete
  22. Attend The Business Analytics Course From ExcelR. Practical Business Analytics Certification Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Business Analytics Course
    Data Scientist Course

    ReplyDelete

Like us on Facebook

Site Visitor

Powered by Blogger.