<?php
class Page {
function getPage($urlOfPage){
$result = mysql_query('SELECT category, title FROM rs-planet WHERE url = "'. mysql_real_escape_string($urlOfPage));
if(mysql_num_rows($result) === 0){
header('HTTP/1.0 404 Not Found');
exit;
}
else{
return $page[] = mysql_fetch_array($result);
}
}
}
?>
And I have this errors:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean
given in C:\xampp\htdocs\rs-planet\classes\page.php on line 6Warning: mysql_fetch_array() expects parameter 1 to be resource,
boolean given in C:\xampp\htdocs\rs-planet\classes\page.php on line 11
And I don’t see the problem…
And if I do var_dump @ $result I get a boolean. (If it’s founded @ the db it gives true, if it isn’t it gives me false.)
PS. Sorry for my bad English, my main language is Dutch.
EDIT:
var_dump(mysql_error) =
string(152) “You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near ‘”index’ at line 1”
mysql_queryreturns false if the query cannot be executed (i.e. bad syntax). Try surroundingrs-planetwith backticks:I’m thinking the
-in the table name is screwing up the syntax.EDIT: Also, PDO makes it much easier to debug these issues since you don’t need to use
mysql_error()to get the error message – it’s included in the Exception thrown by PDO.http://php.net/manual/en/book.pdo.php
SECOND EDIT: Actually the problem is likely the missing quote. Fixed my code, but see the other answers…