rosse88 Posted August 21, 2012 Share Posted August 21, 2012 Hi there, and in advance thank you for any assistance. I ran into a problem with some coding and after running a fair about of debugging I still cannot manage to get it working. The error message is as follows: Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 14 in /Users/Home/Sites/functions/users.php on line 6 I understand that this is considered a common error, but even after looking at everything, this is becoming very frustrating. The function this is in regards to is the following: function logs_id_from_schooluser($school_user = false, $school_id = false) { if ($school_user || $school_id) { $school_user = sanitize($school_user); $school_id = (int)$school_id; return (mysql_result(mysql_query("SELECT `logs_id` FROM `school_logs` WHERE `school_user` = '$school_user' AND `school_id` = '$school_id'"),0, 'logs_id')); } else { echo 'There seems to be a parameter missing!'; } } What is frustrating is that it is clearing this function without any issues (if it weren't then logically it would be unable to reach the previous): function school_user_exists($school_user = false, $school_id = false) { if($school_user || $school_id) { $school_user = sanitize($school_user); $school_id = (int)$school_id; $query = mysql_query("SELECT COUNT(`logs_id`) FROM `school_logs` WHERE `school_user` = '$school_user' AND `school_id` = '$school_id'"); return (mysql_result($query, 0) == 1) ? true : false; } else { echo 'Something is amiss!'; } } Ive started to wonder if the count function in school_users_exist is somehow being artificially passed. I can post more of the surrounding code if that will help. Thank you all again. Im at my wits end, most likely because I have been looking at it for far too long. Quote Link to comment Share on other sites More sharing options...
Barand Posted August 21, 2012 Share Posted August 21, 2012 Could be the query failed. Check the value of mysql_error() Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 21, 2012 Share Posted August 21, 2012 If there's no error in mysql_error, your query is probably returning an empty results set. Quote Link to comment Share on other sites More sharing options...
Barand Posted August 21, 2012 Share Posted August 21, 2012 A COUNT() query should always return a row even if the count is 0 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 21, 2012 Share Posted August 21, 2012 Right, but the COUNT() query isn't the one the OP indicated was producing the error, if I read the post correctly. Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 21, 2012 Share Posted August 21, 2012 I think he's saying that no rows are being found, which is causing the error. The OP then ran the count query and it worked, so he thinks there are rows. In reality, the count is returning a count of 0. Quote Link to comment Share on other sites More sharing options...
rosse88 Posted August 21, 2012 Author Share Posted August 21, 2012 Thank you for all of the replies. On the error this is the warning yielded: Warning: end() expects parameter 1 to be array, boolean given in /Users/Home/Sites/functions/users.php on line 7 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 21, 2012 Share Posted August 21, 2012 That part of the code isn't included in your post. Quote Link to comment Share on other sites More sharing options...
rosse88 Posted August 21, 2012 Author Share Posted August 21, 2012 My apologize, it referred to this specific line within the logs_id function: return end(mysql_fetch_array($query)); within this code to check it: function logs_id_from_schooluser($school_user = false, $school_id = false) { if ($school_user || $school_id) { $school_user = sanitize($school_user); $school_id = (int)$school_id; $query = mysql_query("SELECT `logs_id` FROM `school_logs` WHERE `school_user` = '$school_user' AND `school_id` = '$school_id'") or die(mysql_error()); return end(mysql_fetch_array($query)); } else { echo 'There seems to be a parameter missing!'; } } Quote Link to comment Share on other sites More sharing options...
Barand Posted August 21, 2012 Share Posted August 21, 2012 Don't nest mysql functions. Change return (mysql_result(mysql_query("SELECT `logs_id` FROM `school_logs` WHERE `school_user` = '$school_user' AND `school_id` = '$school_id'"),0, 'logs_id')); to $res = mysql_query("SELECT `logs_id` FROM `school_logs` WHERE `school_user` = '$school_user' AND `school_id` = '$school_id'") or die(mysql_error()); return mysql_result($res, 0, 'logs_id'); Quote Link to comment Share on other sites More sharing options...
rosse88 Posted August 21, 2012 Author Share Posted August 21, 2012 I actually did a little more digging with some more help and found this. Apparently the school_id isn't being passed through. The actual query being passed appears to be (user name is blocked out by me but is correct): SELECT `logs_id` FROM `school_logs` WHERE `school_user` = '*******' AND `school_id` = '0' Which leads me to another issue, where I hope I do not create a run on topic. I'll post the constraints of the page and the menus really fast, just to get some feedback on whether this is in fact the issue: <?php if(empty($_POST) === false) { $school_user = $_POST['school_user']; $school_pass = $_POST['school_pass']; $school_id = $_POST['school']; if (empty($school_user) === true || empty($school_pass) === true) { $errors[] = 'You must enter a username and password.'; } else if (school_user_exists($school_user,$school_id) === false) { $errors[] = 'We were unable to locate that username. Please contact your school.'; } else { $school_login = school_login($school_user, $school_pass); if ($school_login === false) { $errors[] = 'Either the username or password is incorrect.'; } else { echo 'SUCCESS!'; exit(); } } } else { $errors[] = ''; } ?> <?php include 'headers/userheader.php';?> <h1><?php echo '' . $lang['Follow steps 1 through 7.'] . '';?></h1><br> <?php if (isset($_GET['success']) === true && empty($_GET['success']) === true) { echo '<p2>Your school has been successfully added!</p2>'; } else { if (empty($errors) === false) { echo output_errors($errors); } ?> <form id="schoolselect" action="" method="post"> <ul> 1. <?php echo '' . $lang['Country'] . '';?>:<br> <li> <select name="country"> <?php $country_query = "SELECT country_id, country_name FROM school_country"; $country_result = mysql_query($country_query); while($country = mysql_fetch_array($country_result)) { if($_POST['country'] == $country['country_id'] ) { echo '<option selected value="' . $country['country_id'] . '">' . $country['country_name'] . '</option>'; } else { echo '<option value="' . $country['country_id'] . '">' . $country['country_name'] . '</option>'; } } ?> </select> <input type="submit" name="submit" value="<?php echo '' . $lang['Refine'] . '';?>" /><br><br> </li> 2. <?php echo '' . $lang['Region or State'] . '';?>:<br> <li> <select name="state"> <?php if($_POST['submit']) { echo $_POST['country']; $state_query = "SELECT state_id, state_name FROM school_state WHERE country_id = '{$_POST[country]}'"; $state_result = mysql_query($state_query); while($state = mysql_fetch_array($state_result)) { if($_POST['state'] == $state['state_id'] ) { echo '<option selected value="' . $state['state_id'] . '">' . $state['state_name'] . '</option>'; } else { echo '<option value="' . $state['state_id'] . '">' . $state['state_name'] . '</option>'; } } } ?> </select> <input type="submit" name="submit" value="<?php echo '' . $lang['Refine'] . '';?>" /><br><br> </li> 3. <?php echo '' . $lang['City'] . '';?>:<br> <li> <select name="city"> <?php if($_POST['submit']) { echo $_POST['state']; $city_query = "SELECT city_id, city_name FROM school_city WHERE state_id = '{$_POST[state]}'"; $city_result = mysql_query($city_query); while($city = mysql_fetch_array($city_result)) { if($_POST['city'] == $city['city_id'] ) { echo '<option selected value="' . $city['city_id'] . '">' . $city['city_name'] . '</option>'; } else { echo '<option value="' . $city['city_id'] . '">' . $city['city_name'] . '</option>'; } } } ?> </select> <input type="submit" name="submit" value="<?php echo '' . $lang['Refine'] . '';?>" /><br><br> </li> 4. <?php echo '' . $lang['School'] . '';?>:<br> <li> <select name="school"> <?php if($_POST['submit']) { echo $_POST['city']; $school_query = "SELECT school_id, school_name FROM school_list WHERE city_id = '{$_POST[city]}'"; $school_result = mysql_query($school_query); while($school = mysql_fetch_array($school_result)) { if($_POST['school'] == $school['school_id'] ) { echo '<option selected value="' . $school['school_id'] . '">' . $school['school_name'] . '</option>'; } else { echo '<option value="' . $school['school_id'] . '">' . $school['school_name'] . '</option>'; } } } ?> </select> <input type="submit" name="submit" value="<?php echo '' . $lang['Submit'] . '';?>" /><br><br> </li> 5. <?php echo '' . $lang['School Issued Username'] . '';?>:<br> <li> <input type="text" name="school_user" required<?php if (isset($_POST['school_user']) === true) { echo 'value="', strip_tags($_POST['school_user']), '"'; } ?>><br><br> </li> 6. <?php echo '' . $lang['School Issued Password'] . '';?>:<br> <li> <input type="password" name="school_pass" required> </li> </ul> 7. <input type="submit" name="submit" value="<?php echo '' . $lang['Add School'] . '';?>" /> </form> <?php } include 'footers/userfooter.php';?> If I am not mistaken, this would mean that the school_user_exists function is misbehaving and passing a false value (so to speak). Thank you all for the help thus far. Im certainly attempting to apply/correct what I can in the meantime. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 21, 2012 Share Posted August 21, 2012 Are both arguments required? If they are, your validation logic is flawed. Quote Link to comment Share on other sites More sharing options...
rosse88 Posted August 22, 2012 Author Share Posted August 22, 2012 Just wanted to say that the issue has been resolved. You were absolutely right in that my logic was off. Thank you all for the stupendous support! 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.