Advertisement
Guest User

Untitled

a guest
Aug 29th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.61 KB | None | 0 0
  1. <?php
  2.  
  3. // server info
  4. $server = 'localhost';
  5. $user = 'root';
  6. $pass = '';
  7. $db = 'mysql';
  8.  
  9. // connect to the database
  10. $mysqli = new mysqli($server, $user, $pass, $db);
  11.  
  12. // show errors (remove this line if on a live site)
  13. mysqli_report(MYSQLI_REPORT_ERROR);
  14.  
  15. function renderForm($customer_name = '', $MGMT_IP = '', $Vendor = '', $Version = '', $GUI_User = '', $GUI_Pass = '', $Notes = '', $error = '', $customer_number = '')
  16. { ?>
  17.  
  18. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  19. <html>
  20. <html dir="rtl" lang="ar">
  21. <head>
  22. <title>
  23. <?php if ($customer_number != '') { echo "edit customer record"; } else { echo "New Record"; } ?>
  24. </title>
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  26. </head>
  27. <body>
  28. <h1><?php if ($customer_number != '') { echo "type in the all required fields"; } else { echo "New Record"; } ?></h1>
  29. <?php if ($error != '') {
  30. echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error
  31. . "</div>";
  32. } ?>
  33.  
  34. <form action="" method="post">
  35. <div>
  36. <?php if ($customer_number != '') { ?>
  37. <input type="hidden" name="customer_number" value="<?php echo $customer_number; ?>" />
  38. <p>customer_number: <?php echo $customer_number; ?></p>
  39. <?php } ?>
  40.  
  41. <strong>customer name: *</strong> <input type="text" name="customer_name"
  42. value="<?php echo $customer_name; ?>"/><br/><br/>
  43. <label for="Vendor">vendor</label>
  44. <select name="Vendor">
  45. <option value="Juniper">Juniper</option>
  46. <option value="Fortinet">Fortinet</option>
  47. <option value="Websense">Websense</option>
  48. <option value="F5">F5</option>
  49. <option value="Cisco">Cisco</option>
  50. <option value="Backbox">Backbox</option>
  51. <option value="Radware">Radware</option>
  52. <option value="Orion">Orion</option>
  53. <option value="VM">VM</option>
  54. <option value="EMC">EMC</option>
  55. <option value="Backup">Backup</option>
  56. <option value="HP">HP</option>
  57. <option value="Storage">Storage</option>
  58. <option value="PinApp">PineApp</option>
  59. <option value="RDP">RDP</option>
  60. </select><br/><br/>
  61.  
  62. <strong>MGMT IP: *</strong> <input type="text" name="MGMT_IP"
  63. value="<?php echo $MGMT_IP; ?>"/><br/><br/>
  64. <strong>version: *</strong> <input type="text" name="Version"
  65. value="<?php echo $Version; ?>"/><br/><br/>
  66. <strong>GUI User: *</strong> <input type="text" name="GUI_User"
  67. value="<?php echo $GUI_User; ?>"/><br/><br/>
  68. <strong>GUI Pass: *</strong> <input type="text" name="GUI_Pass"
  69. value="<?php echo $GUI_Pass; ?>"/><br/><br/>
  70. <strong>notes: </strong> <input type="text" name="Notes"
  71. value="<?php echo $Notes; ?>"/>
  72. <p>* FILLUP REUIRED FIELDS</p>
  73. <input type="submit" name="submit" value="Submit" />
  74. </div>
  75. </form>
  76. </body>
  77. </html>
  78.  
  79. <?php }
  80.  
  81. /*
  82.  
  83. EDIT RECORD
  84.  
  85. */
  86.  
  87.  
  88. {
  89. // if the 'customer_number' variable is set in the URL, we know that we need to edit a record
  90. if (isset($_GET['customer_number']))
  91. {
  92. // if the form's submit button is clicked, we need to process the form
  93. if (isset($_POST['submit']))
  94. {
  95. // make sure the 'customer_number' in the URL is valid
  96. if (is_numeric($_POST['customer_number']))
  97. {
  98. // get variables from the URL/form
  99. $customer_number = $_POST['customer_number'];
  100. $customer_name = htmlentities($_POST['customer_name'], ENT_QUOTES);
  101. $Vendor = htmlentities($_POST['Vendor'], ENT_QUOTES);
  102. $MGMT_IP = htmlentities($_POST['MGMT_IP'], ENT_QUOTES);
  103. $Version = htmlentities($_POST['Version'], ENT_QUOTES);
  104. $GUI_User = htmlentities($_POST['GUI_User'], ENT_QUOTES);
  105. $GUI_Pass = htmlentities($_POST['GUI_Pass'], ENT_QUOTES);
  106. $Notes = htmlentities($_POST['Notes'], ENT_QUOTES);
  107.  
  108.  
  109. // check that customer_name and Vendor are both not empty
  110. if ($customer_name == '' || $Vendor == '' || $MGMT_IP == '' || $Version == '' || $GUI_User == '' || $GUI_Pass == '')
  111. {
  112. // if they are empty, show an error message and display the form
  113. $error = 'error: fill up required fields!';
  114. renderForm($customer_name, $Vendor, $MGMT_IP, $Version, $GUI_User, $GUI_Pass, $Notes, $error, $customer_number);
  115. }
  116. else
  117. {
  118. // if everything is fine, update the record in the database
  119. if ($stmt = $mysqli->prepare("UPDATE cloud_team SET customer_name = ?, Vendor = ?, MGMT_IP = ?, Version = ?, GUI_User = ?, GUI_Pass = ?, Notes = ?
  120. WHERE customer_number=?"))
  121. {
  122. $stmt->bind_param("sssssssi", $customer_name, $Vendor, $MGMT_IP, $Version, $GUI_User, $GUI_Pass, $Notes, $customer_number);
  123. $stmt->execute();
  124. $stmt->close();
  125. }
  126. // show an error message if the query has an error
  127. else
  128. {
  129. echo "ERROR: could not prepare SQL statement.";
  130. }
  131.  
  132. // redirect the user once the form is updated
  133. header("Location: view.php");
  134. }
  135. }
  136. // if the 'customer_number' variable is not valid_number, show an error message
  137. else
  138. {
  139. echo "Error!";
  140. }
  141. }
  142. // if the form hasn't been submitted yet, get the info from the database and show the form
  143. else
  144. {
  145. // make sure the 'customer_number' value is valcustomer_number
  146. if (is_numeric($_GET['customer_number']) && $_GET['customer_number'] > 0)
  147. {
  148. // get 'customer_number' from URL
  149. $customer_number = $_GET['customer_number'];
  150.  
  151. // get the recod from the database
  152. if($stmt = $mysqli->prepare("SELECT * FROM cloud_team WHERE customer_number=?"))
  153. {
  154. $stmt->bind_param("i", $customer_number);
  155. $stmt->execute();
  156.  
  157. $stmt->bind_result($customer_number, $customer_name, $Vendor, $MGMT_IP, $Version, $GUI_User, $GUI_Pass, $Notes);
  158. $stmt->fetch();
  159.  
  160. // show the form
  161. renderForm($customer_name, $Vendor, $MGMT_IP, $Version, $GUI_User, $GUI_Pass, $Notes, NULL, $customer_number);
  162.  
  163. $stmt->close();
  164. }
  165. // show an error if the query has an error
  166. else
  167. {
  168. echo "Error: could not prepare SQL statement";
  169. }
  170. }
  171. // if the 'customer_number' value is not valid, redirect the user back to the joomla_31/index.php/juniper page
  172. else
  173. {
  174. header("Location: view.php");
  175. }
  176. }
  177. }
  178. // if the form hasn't been submitted yet, show the form
  179. else
  180. {
  181. renderForm();
  182. }
  183. }
  184. // close the mysqli connection
  185.  
  186. $mysqli->close();
  187. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement