I am new to php and reading a book on this. I cannot follow how S_request is being used by the script page.php to use variable story from the script Index.php.
I thought $request is used to access form variables only but variable story is not a form variable, then how is $request being used to access variable story in page.php? Am i right? Someone please help.
INDEX.PHP
<?php
include_once('db_fns.php');
include_once('header.php');
$handle = db_connect();
$pages_sql = 'select * from pages order by code';
$pages_result = $handle->query($pages_sql);
echo '<table border="0" width="400">';
while ($pages = $pages_result->fetch_assoc())
{
$story_sql = "select * from stories
where page = '{$pages['code']}'
and published is not null
order by published desc";
$story_result = $handle->query($story_sql);
if ($story_result->num_rows)
{
$story = $story_result->fetch_assoc();
echo "<tr>
<td>
<h2>{$pages['description']}</h2>
<p>{$story['headline']}</p>
<p align='right' class='morelink'>
<a href='page.php?page={$pages['code']}'>
Read more {$pages['code']} ...
</a>
</p>
</td>
<td width='100'>";
if ($story['picture'])
{
echo '<img src="resize_image.php?image=';
echo urlencode($story[picture]);
echo '&max_width=80&max_height=60" />';
}
echo '</td></tr>';
}
}
echo '</table>';
include_once('footer.php');
?>
PAGE.PHP
<?php
if (!isset($REQUEST['page'])&&!isset($REQUEST['story']))
{
header('Location: index.php');
exit;
}
$page = $REQUEST['page'];
$story = intval($REQUEST['story']);
include_once('db_fns.php');
include_once('header.php');
$handle = db_connect();
if($story)
{
$query = "select from stories
where id = '$story' and
published is not null";
}
else
{
$query = "select from stories
where page = '$page' and
published is not null
order by published desc";
}
$result = $handle->query($query);
while ($story = $result->fetch_assoc())
{
// headline
echo "<h2>{$story['headline']}</h2>";
//picture
if ($story['picture'])
{
echo '<div style="float:right; margin:0px 0px 6px 6px;">';
echo '<img src="resize_image.php?image=';
echo urlencode($story[picture]);
echo '&max_width=200&max_height=120" align = right/></div>';
}
// byline
$w = get_writer_record($story['writer']);
echo '<br /><p class="byline">';
echo $w[full_name].', ';
echo date('M d, H:i', $story['modified']);
echo '</p>';
// main text
echo $story['story_text'];
}
include_once('footer.php');
?>