Guest User

Untitled

a guest
Dec 17th, 2021
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. <?php
  2. if (isset($_GET['id'])) {
  3. include "db_conn.php";
  4.  
  5. function validate($data){
  6. $data = trim($data);
  7. $data = stripslashes($data);
  8. $data = htmlspecialchars($data);
  9. return $data;
  10. }
  11.  
  12. $id = validate($_GET['id']);
  13.  
  14. $sql = "SELECT * FROM users WHERE id=$id";
  15. $result = mysqli_query($conn, $sql);
  16.  
  17. if (mysqli_num_rows($result) > 0) {
  18. $row = mysqli_fetch_assoc($result);
  19. }else {
  20. header("Location: read.php");
  21. }
  22.  
  23. }else if(isset($_POST['update'])) {
  24. include "../db_conn.php";
  25. function validate($data){
  26. $data = trim($data);
  27. $data = stripslashes($data);
  28. $data = htmlspecialchars($data);
  29. return $data;
  30. }
  31.  
  32. $customer_name = validate($_POST['customer_name']);
  33. $customer_email = validate($_POST['customer_email']);
  34. $customer_mobile = validate($_POST['customer_mobile']);
  35. $poNum = validate($_POST['poNum']);
  36. $site_name = validate($_POST['site_name']);
  37. $street1 = validate($_POST['street1']);
  38. $id = validate($_POST['id']);
  39.  
  40. if (empty($customer_name)) {
  41. header("Location: ../update.php?id=$id&error=Name is required");
  42. }else if (empty($customer_email)) {
  43. header("Location: ../update.php?id=$id&error=Email is required");
  44. }else if (empty($customer_mobile)) {
  45. header("Location: ../update.php?id=$id&error=Mobile is required");
  46. }else if (empty($poNum)) {
  47. header("Location: ../update.php?id=$id&error=PO Number is required");
  48. }else if (empty($site_name)) {
  49. header("Location: ../update.php?id=$id&error=Site Name is required");
  50. }else if (empty($street1)) {
  51. header("Location: ../update.php?id=$id&error=Address is required");
  52. }else {
  53.  
  54. $sql = "UPDATE users
  55. SET customer_name='$customer_name', customer_email='$customer_email',
  56. customer_mobile='$customer_mobile', poNum='$poNum',
  57. site_name='$site_name', street1='$street1'
  58. WHERE id=$id ";
  59.  
  60. $result = mysqli_query($conn, $sql);
  61. if ($result) {
  62. header("Location: ../read.php?success=Successfully Updated");
  63. }else {
  64. header("Location: ../update.php?id=$id&error=Unknown error occurred&$user_data");
  65. }
  66. }
  67. }else{
  68. header("Location: read.php");
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment