Advertisement
Guest User

tpk

a guest
Feb 15th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "";
  5. $dbname = "bit2018";
  6. $msg ='';
  7. $std_id = $_GET['id'];
  8. // Create connection
  9. $conn = mysqli_connect($servername, $username, $password, $dbname);
  10. // Check connection
  11. if (!$conn) {
  12. die("Connection failed: " . mysqli_connect_error());
  13. }
  14.  
  15. if(isset($_POST['updatebtn']))
  16. {
  17. $std_fname = $_POST['std_fname'];
  18. $std_lname = $_POST['std_lname'];
  19. $std_roll = $_POST['std_roll'];
  20. $std_contact = $_POST['std_contact'];
  21. $std_address = $_POST['std_address'];
  22.  
  23. $sqlQuery = "UPDATE students SET std_fname='$std_fname', std_lname='$std_lname', std_roll='$std_roll', std_contact='$std_contact', std_address='$std_address' WHERE std_id='$std_id'";
  24. if(mysqli_query($conn,$sqlQuery))
  25. {
  26. $msg = "Information Updated Successfully";
  27. }
  28. else
  29. {
  30. $msg = "Problem in Updating Data";
  31. }
  32. }
  33.  
  34.  
  35. $selectQuery = "SELECT * FROM students WHERE std_id='$std_id'";
  36. $result = mysqli_query($conn, $selectQuery);
  37. $info = mysqli_fetch_assoc($result);
  38.  
  39. ?>
  40. <h1 style="color: green"><?php echo $msg; ?> </h1>
  41. <fieldset>
  42. <legend>Student Update Form</legend>
  43. <form method="POST">
  44. <b>First Name: </b> <input type="text" value="<?php echo $info['std_fname']; ?>" name="std_fname" required>
  45. <hr>
  46.  
  47. <b>Last Name: </b> <input type="text" value="<?php echo $info['std_lname']; ?>" name="std_lname" required>
  48. <hr>
  49.  
  50. <b>Roll: </b> <input type="text" value="<?php echo $info['std_roll']; ?>" name="std_roll" required>
  51. <hr>
  52.  
  53. <b>Contact: </b> <input type="text" name="std_contact" value="<?php echo $info['std_contact']; ?>" required>
  54. <hr>
  55.  
  56. <b>Address: </b> <input type="text" name="std_address" value="<?php echo $info['std_address']; ?>" required>
  57. <hr>
  58.  
  59. <button type="submit" name="updatebtn">Update</button>
  60. </form>
  61. </fieldset>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement