Jump to content

Troubling issue


rosse88

Recommended Posts

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.

Link to comment
Share on other sites

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!';
    }
}

Link to comment
Share on other sites

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');

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.