Advertisement
Guest User

Untitled

a guest
May 27th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <link href="css/bootstrap.min.css" rel="stylesheet">
  6. <script src="js/bootstrap.min.js"></script>
  7. </head>
  8.  
  9. <?php
  10. require 'database.php';
  11.  
  12. $id = null;
  13. if ( !empty($_GET['id'])) {
  14. $id = $_REQUEST['id'];
  15. }
  16.  
  17. if ( null==$id ) {
  18. header("Location: index.php");
  19. }
  20.  
  21. if ( !empty($_POST)) {
  22. // keep track validation errors
  23. $nameError = null;
  24. $emailError = null;
  25. $mobileError = null;
  26.  
  27. // keep track post values
  28. $name = $_POST['name'];
  29. $email = $_POST['email'];
  30. $mobile = $_POST['mobile'];
  31.  
  32. // validate input
  33. $valid = true;
  34. if (empty($name)) {
  35. $nameError = 'Please enter Name';
  36. $valid = false;
  37. }
  38.  
  39. if (empty($email)) {
  40. $emailError = 'Please enter Email Address';
  41. $valid = false;
  42. } else if ( !filter_var($email,FILTER_VALIDATE_EMAIL) ) {
  43. $emailError = 'Please enter a valid Email Address';
  44. $valid = false;
  45. }
  46.  
  47. if (empty($mobile)) {
  48. $mobileError = 'Please enter Mobile Number';
  49. $valid = false;
  50. }
  51.  
  52. // update data
  53. if ($valid) {
  54. $pdo = Database::connect();
  55. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  56. $sql = "UPDATE customers set name = ?, email = ?, mobile =? WHERE id = ?";
  57. $q = $pdo->prepare($sql);
  58. $q->execute(array($name,$email,$mobile,$id));
  59. Database::disconnect();
  60. header("Location: index.php");
  61. }
  62. } else {
  63. $pdo = Database::connect();
  64. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  65. $sql = "SELECT * FROM customers where id = ?";
  66. $q = $pdo->prepare($sql);
  67. $q->execute(array($id));
  68. $data = $q->fetch(PDO::FETCH_ASSOC);
  69. $name = $data['name'];
  70. $email = $data['email'];
  71. $mobile = $data['mobile'];
  72. Database::disconnect();
  73. }
  74. ?>
  75.  
  76. <body>
  77. <div class="container">
  78.  
  79. <div class="span10 offset1">
  80. <div class="row">
  81. <h3>Update a Customer</h3>
  82. </div>
  83.  
  84. <form class="form-horizontal" action="update.php?id=<?php echo $id?>" method="post">
  85. <div class="control-group <?php echo !empty($nameError)?'error':'';?>">
  86. <label class="control-label">Name</label>
  87. <div class="controls">
  88. <input name="name" type="text" placeholder="Name" value="<?php echo !empty($name)?$name:'';?>">
  89. <?php if (!empty($nameError)): ?>
  90. <span class="help-inline"><?php echo $nameError;?></span>
  91. <?php endif; ?>
  92. </div>
  93. </div>
  94. <div class="control-group <?php echo !empty($emailError)?'error':'';?>">
  95. <label class="control-label">Email Address</label>
  96. <div class="controls">
  97. <input name="email" type="text" placeholder="Email Address" value="<?php echo !empty($email)?$email:'';?>">
  98. <?php if (!empty($emailError)): ?>
  99. <span class="help-inline"><?php echo $emailError;?></span>
  100. <?php endif;?>
  101. </div>
  102. </div>
  103. <div class="control-group <?php echo !empty($mobileError)?'error':'';?>">
  104. <label class="control-label">Mobile Number</label>
  105. <div class="controls">
  106. <input name="mobile" type="text" placeholder="Mobile Number" value="<?php echo !empty($mobile)?$mobile:'';?>">
  107. <?php if (!empty($mobileError)): ?>
  108. <span class="help-inline"><?php echo $mobileError;?></span>
  109. <?php endif;?>
  110. </div>
  111. </div>
  112. <div class="form-actions">
  113. <button type="submit" class="btn btn-success">Update</button>
  114. <a class="btn" href="index.php">Back</a>
  115. </div>
  116. </form>
  117. </div>
  118.  
  119. </div> <!-- /container -->
  120. </body>
  121. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement