winter-ale Posted January 4, 2015 Share Posted January 4, 2015 Hello all, looking for some help here as I seem to be fairly stuck... this yields no results at all and I give up, I need help! The user should be able to select an employee from a select field, and based on their selected we should be able to grab the start time and end time of that empoyee, which resides on the database. My form: <form action=".php" name="absence" id="absence" method="post"> Employee: <select name="empid" class="clockinputs" required> <option value=""></option> <option value='20'>Bob Jones</option> <option value='13'>Bob Phones</option> <option value='93'>Bob Lomes</option> <option value='30'>Bob Somes</option> <option value='107'>Bob Pomes</option> <option value='74'>Bob Womes</option> </select> Shift Start: <input type="text" name="startshift" id="startshift" class="clockinputs" data-inputmask="'mask': '99:99:99'" required> Shift End: <input type="text" name="endshift" id="endshift" class="clockinputs" data-inputmask="'mask': '99:99:99'" required> <input type="hidden" name="eid" value="<?php echo $row{'EID'}; ?>"> <input type="submit" value="Save"> </form> Javascript: <script type="text/javascript"> jQuery(document).ready(function(){ jQuery('#empid').live('change', function(event) { $.ajax({ url : 'absence-get.php', type : 'POST', dataType: 'json', data : $('#absence').serialize(), success: function( data ) { for(var id in data) { $(id).val( data[id] ); } } }); }); }); </script> And absence-get.php: <?php $e = $_POST['empid']; $result = mysql_query("SELECT * FROM employees WHERE EID='$e' "); $row = mysql_fetch_array($result, MYSQL_ASSOC) $startshift = $row{'startshift'}; $endshift = $row{'endshift'}; $arr = array( 'input#startshift' => $startshift , 'input#endshift' => $endshift ); echo json_encode( $arr ); ?> Anyone spot anything? Thank you! Quote Link to comment Share on other sites More sharing options...
requinix Posted January 4, 2015 Share Posted January 4, 2015 You didn't give the the "empid" ID your code expects. Quote Link to comment Share on other sites More sharing options...
hansford Posted January 4, 2015 Share Posted January 4, 2015 In jQuery, the live() method is deprecated. The on() method is the current preferred method. The mysql code you're using is deprecated. The preferred way is Mysqli or PDO. Quote Link to comment Share on other sites More sharing options...
winter-ale Posted January 4, 2015 Author Share Posted January 4, 2015 You didn't give the <select> the "empid" ID your code expects. Thanks, I've added this, but still no resuts. In jQuery, the live() method is deprecated. The on() method is the current preferred method. The mysql code you're using is deprecated. The preferred way is Mysqli or PDO. Regarding the on() method, I am not familiar... if you have any details please let me know. Regarding mysqli, I am aware, but not about to start mid way through a rather large application. Quote Link to comment Share on other sites More sharing options...
hansford Posted January 4, 2015 Share Posted January 4, 2015 For the jQuery, simply change live() to on() For the Mysql - Every line you write today will have to be changed sooner or later because it simply won't parse one day. Quote Link to comment Share on other sites More sharing options...
wezhind Posted January 4, 2015 Share Posted January 4, 2015 (edited) Hi, I could be wrong, but is the issue to do with you using curly braces instead of square brackets in the following line in absence-get.php: $startshift = $row{'startshift'}; $endshift = $row{'endshift'}; I would have thought it should be: $startshift = $row['startshift']; $endshift = $row['endshift']; AND the same with this line in your form: <input type="hidden" name="eid" value="<?php echo $row{'EID'}; ?>"> Good luck. Edited January 4, 2015 by wezhind 1 Quote Link to comment Share on other sites More sharing options...
winter-ale Posted January 4, 2015 Author Share Posted January 4, 2015 Hi, I could be wrong, but is the issue to do with you using curly braces instead of square brackets in the following line in absence-get.php: Good luck. No change... thanks though. Cant figure this out! Quote Link to comment Share on other sites More sharing options...
CroNiX Posted January 4, 2015 Share Posted January 4, 2015 Maybe you should post your current code with the changes you've implemented. 1 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted January 4, 2015 Share Posted January 4, 2015 your absence-get.php page doesn't show any code making a database connection and the items wezhind found would have been throwing php errors.for the time being, forget about using ajax, just have your html form submit to the absence-get.php page and get both parts working without any errors, retrieving and echoing the expected data.edit: the posted code, even after correcting the syntax errors that wezhind found, throws this fatal parse error - Parse error: syntax error, unexpected '$startshift' (T_VARIABLE) in your_path\absence-get.php on line 7 and doesn't even run. you are missing a ; on the preceding line. Quote Link to comment Share on other sites More sharing options...
Solution winter-ale Posted January 10, 2015 Author Solution Share Posted January 10, 2015 thanks for the help everyone! it's been sorted. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.