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.
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;
}
The following is the output of the page I'm using to debug the function.
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.
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.
The following function is called be the is_owned(), but is not likely to be relevant, as it seems to be functional.
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;
}
Thank you very much for your assistance.
Edit: Additionally, this is the output of the test page when it is supposed to return true:
! 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.