unemployment Posted April 17, 2011 Share Posted April 17, 2011 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233933-function-errors/ Share on other sites More sharing options...
Pikachu2000 Posted April 17, 2011 Share Posted April 17, 2011 The query is failing and returning a boolean FALSE. Use mysql_error(), and echo the query string to see what the problem is. Quote Link to comment https://forums.phpfreaks.com/topic/233933-function-errors/#findComment-1202453 Share on other sites More sharing options...
unemployment Posted April 17, 2011 Author Share Posted April 17, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/233933-function-errors/#findComment-1202457 Share on other sites More sharing options...
JasonLewis Posted April 17, 2011 Share Posted April 17, 2011 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 ==). Quote Link to comment https://forums.phpfreaks.com/topic/233933-function-errors/#findComment-1202463 Share on other sites More sharing options...
unemployment Posted April 17, 2011 Author Share Posted April 17, 2011 I was using = instead of == in my php code... dumb mistake. Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/233933-function-errors/#findComment-1202465 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.