Guest User

Untitled

a guest
Nov 2nd, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. class database{
  2.  
  3. private $connection,
  4. $HOST = 'localhost',
  5. $USERNAME = 'root',
  6. $PASSWORD = '',
  7. $DBNAME = 'bm-massage',
  8. $query = null;
  9.  
  10. public function __construct(){
  11. $this->connection = new mysqli($this->HOST,$this->USERNAME,$this->PASSWORD,$this->DBNAME) or die('failed to connect');
  12. }
  13.  
  14.  
  15. public function update_massage_place($name,$capacity,$address,$id){
  16. $this->query = "UPDATE massage_places SET MassagePlaceName = ?, Capacity = ?, MassagePlaceAddress = ? WHERE MassagePlaceID = ?";
  17. $statement = $this->connection->prepare($this->query);
  18. $statement->bind_param('sisi',$name,$capacity,$address,$id);
  19. $statement->execute();
  20.  
  21. }
  22. }
  23.  
  24. <?php
  25.  
  26. class input{
  27.  
  28. public static function get($name){
  29. if(isset($_POST[$name])){
  30. return $_POST[$name];
  31. }else if(isset($_GET[$name])){
  32. return $_GET[$name];
  33. }else{
  34. return false;
  35. }
  36. }
  37.  
  38. }
  39. ?>
  40.  
  41. <?php
  42.  
  43. require_once 'core/init.php';
  44. require_once 'templates/header.php';
  45.  
  46. $id = input::get('id');
  47.  
  48. ?>
  49. <link rel="stylesheet" type="text/css" href="styles/view-place-detail-style.css">
  50. <title>View Place Detail</title>
  51.  
  52. <script type="text/javascript">
  53.  
  54. $(document).ready(function(){
  55.  
  56. $('#update-massage-place-form').submit(function(event){
  57. event.preventDefault();
  58. var name = $('#name').val();
  59. var capacity = $('#capacity').val();
  60. var address = $('#address').val();
  61.  
  62. $('.error-massage').load('view-place-detail-validation.php?id=<?php $id?>',{
  63. name : name,
  64. capacity : capacity,
  65. address : address,
  66. });
  67. });
  68.  
  69. });
  70.  
  71. </script>
  72.  
  73.  
  74. <div class="container" style="margin-left: 0">
  75. <?php echo $db->get_massage_place_name_admin($id) ?>
  76.  
  77. <form id="update-massage-place-form" autocomplete="off" method="POST">
  78. <label>Massage Place Name</label> <br>
  79. <input id='name' type="text" name="update-place-name" value="<?php echo $db->get_massage_place_name_admin_textinput($id) ?>"><br>
  80. <label>Capacity (per day)</label><br>
  81. <input id='capacity' type="text" name="update-place-capacity" value='<?php echo $db->get_massage_place_capacity_admin($id) ?>'><br>
  82. <label>Address</label><br>
  83. <input id='address' type="text" name="update-address" value=" <?php echo $db->get_massage_place_address_admin($id) ?>"><br><br>
  84. <button type="submit">Update</button>
  85. <div class="error-massage">
  86.  
  87. </div>
  88. </form>
  89.  
  90. </div>
  91.  
  92. <?php
  93. require_once 'core/init.php';
  94.  
  95. $name = input::get('name');
  96.  
  97. $address = input::get('address');
  98.  
  99. $capacity = input::get('capacity');
  100.  
  101. $id = input::get('id');
  102.  
  103. if(empty($name)) echo "Massage place name must be filled!";
  104. else if (empty($address)) echo "Massage place address must be filled!";
  105. else if (empty($capacity)) echo "Capacity must be filled!";
  106. else if (!is_numeric($capacity)) echo "Capacity must be number!";
  107. else{
  108. $db->update_massage_place($name,$capacity,$address,$id);
  109. echo '<script>alert("Update massage place success!")
  110. window.location.href = "home.php?update_success";
  111. ';
  112. }
  113. ?>
Add Comment
Please, Sign In to add comment