Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. Error: UPDATE contracts set `client_type`=?, `client_details`=? WHERE `id`= ?
  2. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?, `client_details`=? WHERE `id`= ?' at line 1
  3. Updated
  4.  
  5. $query = "UPDATE contracts set `client_type`=?, `client_details`=? WHERE `id`= ?";
  6.  
  7. <?php
  8. require("config.php");
  9. $id = filter_input(INPUT_GET, 'id');
  10. ?>
  11.  
  12. <html>
  13. <head>
  14. <title> Submit a Contract </title>
  15. <meta charset="UTF-8">
  16. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  17. </head>
  18. <body>
  19. <form method="post" action="" enctype="multipart/form-data">
  20.  
  21. ID: <input type="hidden" name="id" value="<?php echo $id; ?>" />
  22. <?php
  23. $sql = "SELECT * FROM contracts WHERE `id` = $id";
  24. $result = $con->query($sql);
  25. $row = $result->fetch_assoc();
  26. $client_type = $row['client_type'];
  27. ?>
  28.  
  29. <label for = "client1">
  30. <input type="radio" name="client_type" id = "client1" value="Division" <?php echo ($client_type == 'Division')? "checked" : "" ?> onclick="toggleDivision()"/> Division
  31. </label>
  32. &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
  33. <label for ="client2">
  34. <input type="radio" name="client_type" id = "client2" value="External" <?php echo ($client_type == 'External')? "checked" : "" ?> onclick="toggleExternal()"/> External
  35. </label>
  36. &nbsp
  37. <input type="text" id="extText" name="client_details2" value="<?php echo $row['client_details']; ?>" disabled />
  38. <br><br>
  39.  
  40. <div id="division">
  41. Division:
  42. <select id="mySelect" name="client_details" onclick="enableTextbox()" disabled>
  43. <option value="Choose" <?php echo $row['client_details'] == 'Choose' ? "selected" : ""; ?> />Choose Division...</option>
  44. <option value="Distribution" <?php echo $row['client_details'] == 'Distribution' ? "selected" : ""; ?> />Distribution</option>
  45. <option value="Transmission" <?php echo $row['client_details'] == 'Transmission' ? "selected" : ""; ?> />Transmission</option>
  46. <option value="Generation" <?php echo $row['client_details'] == 'Generation' ? "selected" : ""; ?> />Generation</option>
  47. <option value="Procument" <?php echo $row['client_details'] == 'Procument' ? "selected" : ""; ?> />Procument</option>
  48. <option value="Other" <?php echo $row['client_details'] == 'Other' ? "selected" : ""; ?> />Others</option>
  49. </select>
  50. <br><br>
  51. Others:<input type="text" id="otherTxt" name="client_details1" value="<?php echo $row['client_details']; ?>" disabled />
  52. <br>
  53. </div>
  54. <br>
  55. <input type="submit" name="submit" value="Submit"/>
  56. </form>
  57.  
  58. <script type="text/javascript">
  59.  
  60. function toggleExternal() {
  61. document.getElementById("extText").disabled = false;
  62.  
  63. var divis_el = document.getElementById("division");
  64. for (var i = 0; i < divis_el.children.length; i++) {
  65. divis_el.children[i].disabled = true;
  66. }
  67. }
  68. function toggleDivision() {
  69. document.getElementById("extText").disabled = true;
  70. var val = document.getElementById("mySelect").selectedIndex;
  71. var divis_el = document.getElementById("division");
  72. for (var i = 0; i < divis_el.children.length; i++) {
  73. divis_el.children[i].disabled = false;
  74. divis_el.children[5].disabled = true;
  75. }
  76. }
  77.  
  78. function enableTextbox() {
  79. var val = document.getElementById("mySelect").selectedIndex;
  80. if (val == 0 || val == 1 ||val == 2 ||val == 3 ||val == 4) { document.getElementById("otherTxt").disabled = true}
  81. if (val == 5) { document.getElementById("otherTxt").disabled = false; }
  82. }
  83. </script>
  84.  
  85. </body>
  86.  
  87. <?php
  88. if(isset($_POST['submit'])) {
  89.  
  90. $client_type = isset($_POST ['client_type']) ? $_POST['client_type'] :null;
  91. $client_details = isset($_POST ['client_details']) ? $_POST['client_details'] :null;
  92.  
  93. if($client_type == 'Division'){
  94. $client_details = isset($_POST ['client_details1']) ? $_POST['client_details1'] :null;
  95. $client_details = isset($_POST ['client_details']) ? $_POST['client_details'] :null;
  96. } else {
  97. $client_details = isset($_POST ['client_details2']) ? $_POST['client_details2'] :null;
  98. }
  99.  
  100. if($client_details == 'Other') {
  101. $client_details = isset($_POST ['client_details1']) ? $_POST['client_details1'] :null;
  102. }
  103. $query = "UPDATE contracts set `client_type`=?, `client_details`=? WHERE `id`= ?";
  104.  
  105. $stmt = $con->prepare($query);
  106.  
  107. $stmt->bind_param("ssi", $client_type, $client_details, $id);
  108. $stmt->execute();
  109.  
  110. if ($con->query($query) === TRUE) {
  111. echo "<br><br> Updated successfully <br>";
  112. echo $query;
  113. } else {
  114. echo "Error: " . $query . "<br>" . $con->error;
  115. }
  116.  
  117. if ($stmt->errno){
  118. echo "FAILURE!!! " . $stmt->error;
  119. } else {
  120. echo "<br>Updated";
  121. }
  122.  
  123. $stmt->close();
  124. $con->close();
  125. }
  126. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement