PHP Function Returning True When It Should Return False
<p>I'm having trouble with a PHP function for a very small WYSIWIG-like app. The following function determines whether a user owns a page. It has print statement for debugging.</p>

<pre><code>function is_owned($sitename, $page_id)
{
    $output = false;

    $result = count(single_row_query(sprintf("SELECT page_id FROM pages WHERE sitename='%s' AND page_id='%s';", addslashes($sitename), addslashes(strval($page_id)))));

    print $result;

    if ($result != 0)
        {$output = true; }

    return $output;
}
</code></pre>

<p>The following is the output of the page I'm using to debug the function.</p>

<pre><code>SELECT sitename FROM session WHERE uid='l8rc8ssri8qr65lqvtfp174s91'
SELECT page_id FROM pages WHERE sitename='Test' AND page_id='132432';
Result: 0
The function has returned true.
</code></pre>

<p>As you can see, the value of $result is 0, but the function still returned true. The SQL statements are included, though the problem doesn't seem to lie there.</p>

<p>The following function is called be the is_owned(), but is not likely to be relevant, as it seems to be functional.</p>

<pre><code>function single_row_query($query)
{
    $database_connection = open_connection();

    $result = mysql_query($query);

    $output = mysql_fetch_array($result);

    $output = $output[0];

    mysql_free_result($result);
    mysql_close($database_connection);

    return $output;
}
</code></pre>

<p>Thank you very much for your assistance.</p>

<p>Edit: Additionally, this is the output of the test page when it is supposed to return true:</p>

<pre><code>! SELECT sitename FROM session WHERE uid='l8rc8ssri8qr65lqvtfp174s91' !
! SELECT page_id FROM pages WHERE sitename='Test' AND page_id='7'; !
Result: 1
The function has returned true.
</code></pre>
