Let's look at this function
function global_nav()
{
$conn = connect(); // DB Connector
$sql = "SELECT * FROM $dbname";
$result = mysql_query($sql);
if(!$result)
{
echo "DB Error, could not process menu items.<br/>MySQL Error: ".mysql_error();
exit;
}
while($row=mysql_fetch_array($result))
{
$id = $row['id'];
$table_name = // Something which i do not know
echo '<li><a class="global" href="article.php?tbl='.$table_name.'&id='.$id.'">'.$row['articleTitle'].'</a></li>';
}
closeconnection($conn);
}
I'm assuming the variable $dbname is coming from "config.php." When you have a variable coming from an outside source you need to use globals.
function global_nav()
{
global $dbname;
$conn = connect(); // DB Connector
$sql = "SELECT * FROM $dbname";
$result = mysql_query($sql);
if(!$result)
{
echo "DB Error, could not process menu items.<br/>MySQL Error: ".mysql_error();
exit;
}
while($row=mysql_fetch_array($result))
{
$id = $row['id'];
$table_name = // Something which i do not know
echo '<li><a class="global" href="article.php?tbl='.$table_name.'&id='.$id.'">'.$row['articleTitle'].'</a></li>';
}
closeconnection($conn);
}
Let's look at the second function
// Retrieves articles
function displayArticle($id)
{
$conn = connect(); // DB Connector
$sql = "SELECT * FROM $table_name WHERE id='$id'";
$result = mysql_query($sql);
if($result)
{
$row = mysql_fetch_assoc($result);
$articleinfo[] = $row;
}
return $articleinfo;
closeconnection($conn);
}
You need to add the variable $table_name to the function's parameters - function displayArticle($id, $table_name)
In articles.php you need to change $info = displayArticle($id); to $info = displayArticle($id, $_GET['tbl']);
You code is very insecure. I suggest adding the tables that you want users access in an array.
The following code would go in articles.php
$tblarr = array('table1', 'table2', 'table3', 'table4');
if(!in_array($_GET['tbl'], $tblarr))
die();