Forum Moderators: coopster

Message Too Old, No Replies

What's wrong with my code?

         

webfoo

12:07 am on Mar 28, 2009 (gmt 0)

10+ Year Member



This code is supposed to pull data from a MySQL database (which is populated) and write it to a page. But it gives me the dreaded "white screen of death"... What's wrong?
-----

<?php
$page=$_REQUEST["page"]; //page variable in URL
if ($page=='') { // if no page was specified.
die("Error - no page was requested."); //kill the rest of the script
}

$con = mysql_connect("localhost","user","pass"); // setting up to connect
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("db_name", $con); //connect to DB

$result = mysql_query("SELECT * FROM `pages` WHERE `name` ='" . $page . "'"); //requests record of page specified in URL
while($row = mysql_fetch_array($result)) // runs query
{
$row['id']=$pageid; //sets DB fields to variables.
$row['name']=$pagename;
$row['title']=$pagetitle;
$row['content']=$pagecontent;
}

echo $pagecontent; //outputs variables to page

mysql_close($con); //closes DB connection

?>

But it don't work.

webfoo

12:21 am on Mar 28, 2009 (gmt 0)

10+ Year Member



I slightly re-arranged the code, and kabam! It worked like a charm. ?

eeek

12:31 am on Mar 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



$row['id']=$pageid; //sets DB fields to variables. 
$row['name']=$pagename;
$row['title']=$pagetitle;
$row['content']=$pagecontent;

Those assignments are backwards.

webfoo

12:50 am on Mar 28, 2009 (gmt 0)

10+ Year Member



Yup. Goes to show what a NooB I am.