0
votes

I am trying to create Pagination using PHP, trying to show 5 records per page. Everything works just fine but when I click Pagination links to go to the next page it show an error message.

Access forbidden!

You don't have permission to access the requested object. It is either read-protected or not readable by the server.

If you think this is a server error, please contact the webmaster.

Error 403

localhost Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30

Here is my code.

<?php
        define("SPP", 5);
    if(isset($_GET['groupname']) && isset($_GET['uniname'])) {
        /* VARS */
        $xpage = 0;
        $content = null;
        $totalProfile;
        $totalPage = 0;
        if(isset($_GET['xpage'])) { $xpage = $_GET['xpage'];    }
        $start = $xpage*SPP;
        $end = $start+SPP;
        include("protected/config.php");
        include("protected/class.db.php");
        include("protected/publicLang.php");

        $newSearch = new DB();
        $newSearch->query("SELECT username, university,bgroup, (SELECT COUNT(id) FROM donors) AS totalProfile FROM donors WHERE bgroup = :bgroup LIMIT " . $start . ", " . $end . " ");
        $newSearch->exec(array(
            ":bgroup" => $_GET['groupname']
        ));
        $data = $newSearch->fetch();
        foreach($data as $row) {

            $totalProfile = $row['totalProfile'];
        $content .= '
                <tr>
                <td>' . $row['username'] . '</td>
                <td>'.$row['university'].'</td>
                <td>' . convertBloodIdPublic($row['bgroup']) . '</td>
                <td><button class="btn btn-success">Contact</button></td>
                </tr>   ';
        }
        $totalPage = round($totalProfile/SPP); }
?>
<div class="container records">
<table>
  <tr>
    <th>--</th>
    <th>--</th>
    <th>--</th>
    <th>--</th>
  </tr>
  <?php echo $content ?>
</table>
<ul class="pagination">
<?php
    for($i=1; $i<=$totalPage; $i++) {
        echo '<li><a href="<?php echo ' . $_SERVER['REQUEST_URI'] . '"&xpage"' . $i . ' ?>">' . $i . '</a></li>';}
?>
</ul>
1
You should be able to see pretty clearly by viewing your source that they way you're creating your link URL is wrongPatrick Q

1 Answers

0
votes

403 indicates you are no longer authorized. You probably need to pass some authentication information, this is usually done by POSTING to the URL instead of GET ting it as you are now doing via a bare hyperlink/ element.

I think if you change your code to

<a href="javascript:submit_pagination($i);" >

and add a HIDDEN input element to the encompassing form and add some javascript along the lines

function submit_pagination(i){
    document.forms[0].xpage.value = i;
    document.forms[0].submit();
}

I think it might work. Hope it helps!