Jump to content

Strangest problem ever >:/


TripRev

Recommended Posts

Ok, this really takes the biscuit. I've been trying to debug this for hours and can't find the problem. Basically I have the result of a MySQL query stored in the var $selectList and before this code, the resultset has results in it.

 

if( mysql_result($selectList,0,'viewhash') == 'anyone' ){
        $userCanView = true;
}

 

but after, the fields have all become [empty string]. The fieldnames are intact, just the values have been set to [empty string] by the above code somehow. I've attached a screenshot of the var $selectList dumped out before and after this code. That is all that's between the 2 dumps.

 

Serious driving me insane. Any suggestions much appreciated.

Thanks.

 

[attachment deleted by admin]

Link to comment
Share on other sites

Is $selectList the resource, or an array derived from another call to the resource?  ala. mysql_fetch_assoc...

 

It's the resource, resulting from this:

$selectList = mysql_query('SELECT * FROM the_table WHERE id = '.$_GET['listNum'],$con);

 

Link to comment
Share on other sites

OK, here's more code.

 

<?php
include('funcs.php');
include('dbconnect.php');
session_start();
setDef($userMsg);
setDef($_GET['userMsg']);
setDef($_GET['listNum']);
setDef($_SESSION['uid']);
setDef($_SESSION['viewhash']);
setDef($_SESSION['edithash']);
$selectList = mysql_query('SELECT * FROM the_table WHERE id = '.$_GET['listNum'],$con);
if( mysql_num_rows($selectList) ==1 ){
	$userCanView = false;
	$userCanEdit = false;
	$editPassSet = false;
	if( mysql_result($selectList,0,'viewhash') == 'anyone' ){ // for some reason, this line is setting the resultset $selectList to be blank
		$userCanView = true;
	}
	if( $_SESSION['viewhash'] == mysql_result($selectList,0,'viewhash')){
		$userCanView = true;
	}
	if( $_SESSION['edithash'] == mysql_result($selectList,0,'edithash') ){
		$userCanView = true;
		$userCanEdit = true;
	}
	if( $_SESSION['uid'] == mysql_result($selectList,0,'owner') ){
		$userCanView = true;
		$userCanEdit = true;
	}
	if( mysql_result($selectList,0,'edithash') != 'no' ){
		$editPassSet = true;
	}elseif(mysql_result($selectList,0,'edithash') == $_SESSION['edithash']){
		$userCanEdit = true;
	}
	// load the list's items
	$selectItems = mysql_query('SELECT * FROM the_table WHERE list_id = '.$_GET['listNum'].' AND status = "live" ORDER BY pos ASC, added DESC',$con);
}else{
	$userMsg = '<p class="msgError">That list does not exist. </p>';
	header('Location:user.php?userMsg='.urlencode($userMsg));
}
// redirect user to passreq.php if list requires a view password
if( mysql_result($selectList,0,'owner') != $_SESSION['uid'] ){
	$listViewhash = mysql_result($selectList,0,'viewhash');
	if( ($listViewhash != 'no') && ($listViewhash != 'anyone') && ($listViewhash != $_SESSION['viewhash']) ){
		header('Location:'.$siteURL.'/passreq.php?l='.$_GET['listNum'].'&type=view');
	}
// redirect to login page if user does not have view permission at least
}elseif( !$userCanView ){ 
	$userMsg = '<p class="msgError">You do not have permission to view that list. </p>';
	header('Location:'.$siteURL.'/user.php?userMsg='.urlencode($userMsg));
}
?>

 

Dumping out $selectList before and after the second IF shows that it's happening there.

 

Driving me nuts!

Link to comment
Share on other sites

Found on http://php.net/manual/en/function.mysql-result.php

 

bruce at kaskubar dot com 29-Apr-2011 01:30

The warning against mixing the use of mysql_result with other result set functions is a bit generic. More specifically, mysql_result alters the result set's internal row pointer (at least in a LAMP environment). This is anything but obvious as the nature of the function is random access for grabbing a quick byte. Using mysql_data_seek after some mysql_result calls, before going into a mysql_fetch_array loop, will set things straight.

Link to comment
Share on other sites

To avoid this problem, I always immediately dump the results into an array after I check that results were actually returned.

 

Rather than use multiple mysql_fetch/result etc calls, I simply use the array I've populated and forget about internal pointers :D

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.