post.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. //$modx_user = $modx->user->get('id');
  3. $modx_user = 1;
  4. $con = mysqli_connect("localhost", "root", "R3M0T31", "cropmonitor");
  5. // Check connection
  6. if (mysqli_connect_errno())
  7. {
  8. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  9. }
  10. $result = mysqli_query($con, "SELECT * FROM `client_records` Where `modx_user_id` = $modx_user ");
  11. // mysqli_query returns false if something went wrong with the query
  12. if ($result === FALSE)
  13. {
  14. die(mysqli_error($con)); // TODO: better error handling
  15. }
  16. else
  17. {
  18. ?>
  19. <div class='col-md-12 form-group'>
  20. <label for='client_id'>Current Client</label>
  21. <div><select name='client_id' id='client_id' class='form-control1' onChange='Choice();'>
  22. <option>Select current client or add new client below...</option>
  23. <?php
  24. while ($row=mysqli_fetch_array($result)){
  25. ?>
  26. <option value="<?php echo $row['id']; ?>" id="<?php echo $row['id']; ?>"><?php echo $row['id'] . " - " . $row['client'] . " - " . $row['company']; ?></option>
  27. <?php
  28. }
  29. ?>
  30. </select></div>
  31. </div>
  32. <?php
  33. }
  34. ?>
  35. <script type="text/javascript">
  36. <?php
  37. $index = 0;
  38. while ($row = mysqli_fetch_array($result))
  39. {
  40. ?>
  41. var email[<?php echo $index; ?>] = <?php echo $row['email']; ?>;
  42. var name[<?php echo $index; ?>] = <?php echo $row['name']; ?>;
  43. var company[<?php echo $index; ?>] = <?php echo $row['company']; ?>;
  44. var site_address[<?php echo $index; ?>] = <?php echo $row['site_address']; ?>;
  45. var state_postcode[<?php echo $index; ?>] = <?php echo $row['state_postcode']; ?>;
  46. <?php
  47. $index++;
  48. }
  49. ?>
  50. </script>
  51. <?php
  52. mysqli_close($con);
  53. ?>
  54. <script type="text/javascript">
  55. function Choice() {
  56. y = document.getElementById("client_id");
  57. document.getElementById("email").value = email[y.selectedIndex];
  58. document.getElementById("name").value = name[y.selectedIndex];
  59. document.getElementById("company").value = company[y.selectedIndex];
  60. document.getElementById("site_address").value = site_address[y.selectedIndex];
  61. document.getElementById("state_postcode").value = state_postcode[y.selectedIndex];
  62. }
  63. </script>
  64. <div class="col-md-6 form-group">
  65. <label for="email">Email address<span class="error">*</span></label>
  66. <input type="email" class="form-control" name="email" id="email" value="" required autocomplete="on">
  67. </div>
  68. <div class="col-md-6 form-group">
  69. <label for="client_name">Client Name<span class="error">*</span></label>
  70. <input type="text" class="form-control" name="name" id="name" value="" required autocomplete="on">
  71. </div>
  72. <div class="col-md-6 form-group">
  73. <label for="company_name">Company Name</label>
  74. <input type="text" class="form-control" name="company" id="company" value="" autocomplete="on">
  75. </div>
  76. <div class="col-md-6 form-group">
  77. <label for="site_address">Site Address</label>
  78. <input type="text" class="form-control" name="site_address" id="site_address" value="" autocomplete="on">
  79. </div>
  80. <div class="col-md-6 form-group">
  81. <label for="state_postcode">State & Postcode</label>
  82. <input type="text" class="form-control" name="state_postcode" id="state_postcode" value="" autocomplete="on">
  83. </div>