Jump to content

Function Errors


unemployment

Recommended Posts

Please help me fix these errors in my function.

 

Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 10 in

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in

 

function verify_user_fanned_company($uid, $cid)
{ 
$uid = (int)$uid;

$sql = "
	SELECT
		`company_id`
	FROM `company_fans`
	WHERE `user_id` = {$uid}
	AND `company_id` = {$cid}
";

$query = mysql_query($sql);

$result = mysql_result($query, 0);

$num = mysql_num_rows($result);

if ($num === 1)
{
	return true;
}
}

 

<?php

$is_fanned = verify_user_fanned_company($user_info['uid'], $info["companyid"]);

if ($is_fanned = true)
{

?>
do stuff
<?php

}

?>

Link to comment
https://forums.phpfreaks.com/topic/233933-function-errors/
Share on other sites

The query is failing and returning a boolean FALSE. Use mysql_error(), and echo the query string to see what the problem is.

 

The query is fine.  I removed the result, but this just does not work.  Any thoughts as to why?

 

function verify_user_fanned_company($uid, $cid)
{ 
$uid = (int)$uid;
$cid = (int)$cid;

$sql = "
	SELECT
		`company_id`
	FROM `company_fans`
	WHERE `user_id` = ${uid}
	AND `company_id` = ${cid}
";

$query = mysql_query($sql);

$num = mysql_num_rows($query);

if ($num === 1)
{
	return true;
}
else
{
	return false;
}
}

 

Update:  num == 0 but it's not returning false

Link to comment
https://forums.phpfreaks.com/topic/233933-function-errors/#findComment-1202457
Share on other sites

Have you debugged it, checked your inputs and outputs. Make sure the query is running successfully, like Pikachu2000 has said, and confirm it's working by running it in phpMyAdmin.

 

Personally I wouldn't check for an identical match (with ===), I'd just check if they are equal (with ==).

Link to comment
https://forums.phpfreaks.com/topic/233933-function-errors/#findComment-1202463
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.