I am trying to implement pagination to my site, and the query in red below seems to be failing and I can not for the life of me figure out why <?php
$pagenum = $_GET['pagenum'];
session_start();
if(!session_is_registered(myusername)){
header("location:gradient.php");
}
?>
<?php

$host="mysql14.**********.com"; // Host name
$username="a7616133_quest"; // Mysql username
$password="7904063a"; // Mysql password
$db_name="a7616133_quest"; // Database name
$tbl_name="forum_question"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// get value of id that sent from address bar
$id=$_GET['id'];
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
$pagenum = $_GET['pagenum'];
$username = $_SESSION['myusername'];

?>



<!DOCTYPE html>
<html lang="en">
<head>
<title>$title</title>
<link href="biggins2.css" rel="stylesheet" type="text/css" />
<div id="c2">
<div id="ul1viewtopic">
<ul>
<li id ="li" class="hoverable"><a id="a" class="border-left" href="#">Home</a><div><ul id="subnav"><li id="testing" class="subnava"><a class="subnava" href="#">UFC</a></li><li id="testing2" class="subnava"><a class="subnava" href="#">Strikeforce</a></li><li id="testing3" class="subnava"><a class="subnava" href="#">Pride</a></li><li id="testing" class="subnava"><a class="subnava" href="#">WeC</a></li></ul></div></li>
<li id ="li" class="hoverable"><a id="a" href="#">Videos</a><div><ul id="subnav"><li id="testing" class="subnava"><a class="subnava" href="#">UFC</a></li><li id="testing2" class="subnava"><a class="subnava" href="#">Strikeforce</a></li><li id="testing3" class="subnava"><a class="subnava" href="#">Pride</a></li><li id="testing" class="subnava"><a class="subnava" href="#">WeC</a></li></ul></div></li>
<li id ="li" class="hoverable"><a id="a" href="#">Forums</a></li>
<li id ="li" class="hoverable"><a id="a" href="#">Fighters</a><div><ul id="subnav"><li id="testing" class="subnava"><a class="subnava" href="#">UFC</a></li><li id="testing2" class="subnava"><a class="subnava" href="#">Strikeforce</a></li><li id="testing3" class="subnava"><a class="subnava" href="#">Pride</a></li><li id="testing" class="subnava"><a class="subnava" href="#">WeC</a></li></ul></div></li>
<li id ="li" class="hoverable"><a id="a" href="#">Rankings</a><div><ul id="subnav"><li id="testing" class="subnava"><a class="subnava" href="#">UFC</a></li><li id="testing2" class="subnava"><a class="subnava" href="#">Strikeforce</a></li><li id="testing3" class="subnava"><a class="subnava" href="#">Pride</a></li><li id="testing" class="subnava"><a class="subnava" href="#">WeC</a></li></ul></div></li>
<li id ="li" class="hoverable"><a id="a" href="#">About Us</a><div><ul id="subnav"><li id="testing" class="subnava"><a class="subnava" href="#">UFC</a></li><li id="testing2" class="subnava"><a class="subnava" href="#">Strikeforce</a></li><li id="testing3" class="subnava"><a class="subnava" href="#">Pride</a></li><li id="testing" class="subnava"><a class="subnava" href="#">WeC</a></li></ul></div></li>
</ul>

</div>




<div id="navbarmenu">&nbsp;</div>
<div class="whitespace">&nbsp;</div>


<table class="viewtopictable" width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bordercolor="1" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#141414" class="viewtopic"><strong><? echo $rows['topic']; ?></strong></td>
</tr>

<tr>
<td bgcolor="#141414" class="viewtopic"><? echo $rows['detail']; ?></td>
</tr>



<tr>
<td bgcolor="#141414"><strong>Date/time : </strong><? echo $rows['datetime']; ?></td>
</tr>
</table></td>
</tr>
</table>
<BR>

<?php
$pagenum = $_GET['pagenum'];

if ($pagenum == 0)

{
$pagenum = $_GET['pagenum'];
$pagenum = 1;

}



//Here we count the number of results
$id=$_GET['id'];
//Edit $data to be your query
$tbl_name2="forum_answer";
echo "$pagenum";
$sql_p = "SELECT a_name,a_answer,a_id FROM $tbl_name2 WHERE question_id='$id' ";

$result_p = mysql_query("$sql_p");


$row_info = mysql_num_rows($result_p);



//This is the number of results displayed per page

$page_rows = 4;



//This tells us the page number of our last page

$last = ceil($row_info/$page_rows);



//this makes sure the page number isn't below one, or more than our maximum pages
$pagenum = $_GET['pagenum'];
if ($pagenum < 1)

{
$pagenum = $_GET['pagenum'];
$pagenum = 1;

}

elseif ($pagenum > $last)

{

$pagenum = $last;

}

$pagenum = $_GET['pagenum'];

//This sets the range to display in our query
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;


$tbl_name2="forum_answer"; // Table name

$id=$_GET['id'];
$tbl_name2="forum_answer"; // Switch to table "forum_answer"
$sql2="SELECT a_name,a_answer,a_id FROM $tbl_name2 WHERE question_id='$id' LIMIT $pagenum,$page_rows " ;
$result2=mysql_query($sql2);
while($row2=mysql_fetch_array($result2))
{


echo "<table width=\"400\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"#CCCCCC\">";
echo "<tr>";
echo "<td><table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#FFFFFF\">";

echo "</tr>";
echo "<tr>";
echo "<td width=\"18%\" bgcolor=\"#141414\" class=\"viewtopic\"><strong>Name</strong></td>";
echo "<td width=\"5%\" bgcolor=\"#141414\" class=\"viewtopic\"></td>";
echo "<td width=\"77%\" bgcolor=\"#141414\" class=\"viewtopic\"> {$row2['a_name']}</td>";
echo "</tr>";

echo "<tr>";
echo "<td bgcolor=\"#141414\" class=\"viewtopic\"><strong>Comment</strong></td>";
echo "<td bgcolor=\"#141414\" class=\"viewtopic\">:</td>";
echo "<td bgcolor=\"#141414\" class=\"viewtopic\"> {$row2['a_answer']}</td>";
echo "</tr>";
echo "<tr>";
echo "<td bgcolor=\"#141414\" class=\"viewtopic\"><strong>Date-Time</strong></td>";
echo "<td bgcolor=\"#141414\" class=\"viewtopic\">:</td>";
echo "<td bgcolor=\"#141414\" class=\"viewtopic\">{$row2['a_datetime']}</td>";
echo "</tr>";
echo "</table></td>";
echo "</tr>";
echo "</table><br>";


}

echo "<p>";

$last = ceil($row_info/$page_rows);
// This shows the user what page they are on, and the total number of pages

echo " Page {$_GET['pagenum']} of $rows_info <p>";


// First we check if we are on page one If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.

if ($pagenum == 1)

{

}

else

{

echo " <a href='{$_SERVER['PHP_SELF']}?id=$id?pagenum=$pagenum'> <<-First</a> ";

echo " ";

$previous = $pagenum=+1;

echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";

}


//just a spacer

echo " ---- ";


//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links

if ($pagenum == $last)

{

}

else {
$pagenum = $_GET['pagenum'];
$id=$_GET['id'];
$next = $pagenum + 2;

echo " <a href='{$_SERVER['PHP_SELF']}?id=$id?pagenum=$next'>Next -></a> ";

echo " ";

echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";
}






?>

<?php

$sql3="SELECT view FROM $tbl_name WHERE id='$id'";
$result3=mysql_query($sql3);
$rows=mysql_fetch_array($result3);
$view=$rows['view'];

// if have no counter value set counter = 1
if(empty($view)){
$view=1;
$sql4="INSERT INTO $tbl_name(view) VALUES('$view') WHERE id='$id'";
$result4=mysql_query($sql4);
}

// count more value
$addview=$view+1;
$sql5="update $tbl_name set view='$addview' WHERE id='$id'";
$result5=mysql_query($sql5);
mysql_close();
?>

<BR>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="add_answer.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="18%"><strong>Name</strong></td>
<td width="3%">:</td>
<td width="79%"><input name="a_name" type="text" id="a_name" size="45"></td>
</tr>

<tr>
<td valign="top"><strong>Comment</strong></td>
<td valign="top">:</td>
<td><textarea name="a_answer" cols="45" rows="3" id="a_answer"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="id" type="hidden" value="<? echo $id; ?>"></td>
<td><input type="submit" name="Post" value="Post"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</div>