Hey guys,

I don't see anything wrong in the function but mysql_result is complaining about the parameter value passed to it.

function question_exists($question_id){

    $question_id = (int)$question_id;
    return ( mysql_result(mysql_query("SELECT COUNT('id') from `posts`  WHERE `id`=$question_id"),0) == 0) ? false : true;

    // if the question doesn't exist (equal to ZERO) then return false. Else, return true
}


    $id = '20';

    question_exists($id) =>  this gives me this message "Warning: mysql_result() expects parameter 1 to be resource, boolean given "

Thanks in advance for the help!

Recommended Answers

COUNT('id')

Change single quotes to backticks.

Jump to Post

Disregard.... just DaniWeb changing the post above on me so it's already been done

Jump to Post

All 6 Replies

Any quick help?

COUNT('id')

Change single quotes to backticks.

I tried using (id) but this doesn't seem to be working

Disregard.... just DaniWeb changing the post above on me so it's already been done

Sry for double post I took a look and it won't let me re-edit the above post.

You're getting that error because your query has failed. When it fails it returns FALSE hence the boolean error.

I would break your query down and add error handling to help identify the issue

$sql = "SELECT COUNT(`id`) FROM `posts`  WHERE `id`=$question_id";
$result = mysql_query($sql) or die (mysql_error());

I fixed it already. Cheers for the help, guys.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.