function not functioning
Posted: Tue Jun 05, 2007 9:49 am
hi, i have a problem with a function not working, ive stared at this function for hours, but nothing says im the problem.
this function generate the page requested by getting the data from the database and putting it into variables which are the echoed out in the page where neccassary.
but for some reason it wont work, if i copy the code in the function directly into the place where i call the function it works, but if i put the function name there to call it i just get the following error:
notice: undefined variable in page.php on line 64 (line 64 being where i am outputting the variable)
i get a big list of these notices everywhere i have tried to output the variables of the function.
here is the bit that calls the function providing the page number is set:
here is the function:
thanks for any help.
this function generate the page requested by getting the data from the database and putting it into variables which are the echoed out in the page where neccassary.
but for some reason it wont work, if i copy the code in the function directly into the place where i call the function it works, but if i put the function name there to call it i just get the following error:
notice: undefined variable in page.php on line 64 (line 64 being where i am outputting the variable)
i get a big list of these notices everywhere i have tried to output the variables of the function.
here is the bit that calls the function providing the page number is set:
Code: Select all
if(isset($_GET['page'])){
$page_id =(int)$_GET['page'];
generate_page();
}
else{
$content = "<p><strong>Error:</strong> the page you requested is unavliable,
it is possible it has been delete or you have followed an incorect link.</p>\n";
}here is the function:
Code: Select all
function generate_page(){
$sql = @mysql_query("SELECT title, description,
keywords, content FROM pages
WHERE id='$page_id';");
if(!$sql){
echo "<p>Error: Unable to retrieve page info from database.<br /><br /> Details:" .
mysql_error() . "</p>\n";
}
$data = mysql_fetch_array($sql);
if(!$data){
echo "<p>Error: Unable to retrieve page info from database.<br /><br /> Details:" .
mysql_error() . "</p>\n";
}
$title = $data['title']; //page title
$description = $data['description']; //page description for meta tags
$keywords = $data['keywords']; //keywords for meta tags
$content = $data['content']; //page content
}thanks for any help.