| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- //$modx_user = $modx->user->get('id');
- $modx_user = 1;
- $con = mysqli_connect("localhost", "root", "R3M0T31", "cropmonitor");
- // Check connection
- if (mysqli_connect_errno())
- {
- echo "Failed to connect to MySQL: " . mysqli_connect_error();
- }
- $result = mysqli_query($con, "SELECT * FROM `client_records` Where `modx_user_id` = $modx_user ");
- // mysqli_query returns false if something went wrong with the query
- if ($result === FALSE)
- {
- die(mysqli_error($con)); // TODO: better error handling
- }
- else
- {
- ?>
- <div class='col-md-12 form-group'>
- <label for='client_id'>Current Client</label>
- <div><select name='client_id' id='client_id' class='form-control1' onChange='Choice();'>
- <option>Select current client or add new client below...</option>
- <?php
- while ($row=mysqli_fetch_array($result)){
- ?>
- <option value="<?php echo $row['id']; ?>" id="<?php echo $row['id']; ?>"><?php echo $row['id'] . " - " . $row['client'] . " - " . $row['company']; ?></option>
- <?php
- }
- ?>
- </select></div>
- </div>
- <?php
- }
- ?>
- <script type="text/javascript">
- <?php
- $index = 0;
- while ($row = mysqli_fetch_array($result))
- {
- ?>
- var email[<?php echo $index; ?>] = <?php echo $row['email']; ?>;
- var name[<?php echo $index; ?>] = <?php echo $row['name']; ?>;
- var company[<?php echo $index; ?>] = <?php echo $row['company']; ?>;
- var site_address[<?php echo $index; ?>] = <?php echo $row['site_address']; ?>;
- var state_postcode[<?php echo $index; ?>] = <?php echo $row['state_postcode']; ?>;
- <?php
- $index++;
- }
- ?>
- </script>
- <?php
- mysqli_close($con);
- ?>
- <script type="text/javascript">
- function Choice() {
- y = document.getElementById("client_id");
-
- document.getElementById("email").value = email[y.selectedIndex];
- document.getElementById("name").value = name[y.selectedIndex];
- document.getElementById("company").value = company[y.selectedIndex];
- document.getElementById("site_address").value = site_address[y.selectedIndex];
- document.getElementById("state_postcode").value = state_postcode[y.selectedIndex];
- }
- </script>
-
- <div class="col-md-6 form-group">
- <label for="email">Email address<span class="error">*</span></label>
- <input type="email" class="form-control" name="email" id="email" value="" required autocomplete="on">
- </div>
- <div class="col-md-6 form-group">
- <label for="client_name">Client Name<span class="error">*</span></label>
- <input type="text" class="form-control" name="name" id="name" value="" required autocomplete="on">
- </div>
- <div class="col-md-6 form-group">
- <label for="company_name">Company Name</label>
- <input type="text" class="form-control" name="company" id="company" value="" autocomplete="on">
- </div>
- <div class="col-md-6 form-group">
- <label for="site_address">Site Address</label>
- <input type="text" class="form-control" name="site_address" id="site_address" value="" autocomplete="on">
- </div>
- <div class="col-md-6 form-group">
- <label for="state_postcode">State & Postcode</label>
- <input type="text" class="form-control" name="state_postcode" id="state_postcode" value="" autocomplete="on">
- </div>
|