I am using the code below I found on the internet to grab an id from a url variable and display corresponding body content and it works fine. The problem is I want to pass a page variable through my url instead of the id and use it to pull in content from the db. when I try to mimic this code just substituting the id variable for the page variable i get an unknown column error from mysql. Basically I want a URL that is structured as: content.php?page=somepage ; and then I want to be able to pull in content from the db based upon what page I am on. Does anyone have any help or can point me in the right direction?
Many thanks!
Brenton
<?php
$id = $_GET['id'];
?>
<?php
$sql="SELECT * FROM content WHERE content_id=" . $id;
$result=mysql_query($sql,$conn) or die('Error: '.mysql_error());
$num = mysql_num_rows($result);
$cur = 1;
while ($num >= $cur) {
$row = mysql_fetch_array($result);
$title = $row["title"];
$body = $row["body"];
$header_image = $row["header_image"];
$page = $row["page"];
echo "$body";
$cur++;
}
?>