-2

Here is my code:

                <?php
                    $sql = mysqli_query("SELECT thb_id FROM thumbnails LIMIT 10");
                    $result=mysqli_query($connection,$sql);
                    $count = mysqli_num_rows($sql);
                    if(isset($_GET['thb_id'])) {
                        $page = preg_replace('#[^0-9]#', '', $_GET['thb_id']);
                    } else {
                        $page = 1;
                    }
                    $lastPage = $count;
                    $total = 10;
                        if($page>1)
                        {
                            echo "<a href='project.php?project_id=".($page-1)."' class='button'>PREVIOUS</a>";
                        }
                        if($page!=$total)
                        {
                            echo "<a href='project.php?project_id=".($page+1)."' class='button'>NEXT</a>";
                        }
                    }
                ?>

My portfolio website is using PHP and MYSQL to call data from database, each project has an assigned ID(thb_id), and i am showing 10 projects ($total = 10;). The code above is for my previous and next button, and they are on my "project.php" page. However, it has an internal server error, and i don't know how to fix it.

The updated version:

<?php
                    error_reporting(E_ALL);
                    ini_set('display_errors', true);
                    $sql = ("SELECT thb_id FROM thumbnails LIMIT 10");
                    $result=mysqli_query($connection,$sql);
                    $count = mysqli_num_rows($result);
                    if(isset($_GET['thb_id'])) {
                        $page = preg_replace('#[^0-9]#', '', $_GET['thb_id']);
                    } else {
                        $page = 1;
                    }
                    $lastPage = $count;
                    if($page < 1) {
                        $page = 1;
                    } else if($page > $lastPage) {
                        $page = 1;
                    }
                ?>

The new problem is: both prev and next buttons only take users to project 1(ID = 1).

vivim
  • 1
  • 1
  • 1
    do you have more information regarding the error? as for HTTP 500 barely means anything but somehow the php fails. it can be the database connection fails, or something else.. also, any clues on what `project.php` do? – Bagus Tesa Dec 14 '16 at 02:17
  • "NetworkError: 500 Internal Server Error - http://localhost/portfolio22/project.php?project_id=1", this is what the error says, and the page shows nothing. Project.php contains images and description text of an individual project. – vivim Dec 14 '16 at 02:19
  • 1
    uh.. anything else..? perhaps you could put `error_reporting(E_ALL);` above (below ` – Bagus Tesa Dec 14 '16 at 02:21
  • after i add "error_reporting(E_ALL);" to my code, it reports the same error. – vivim Dec 14 '16 at 02:25
  • 1
    my bad, forgot to tell you to add `ini_set('display_errors', true)`, [source](http://stackoverflow.com/a/17693462/4648586).. hope we get a better error report. – Bagus Tesa Dec 14 '16 at 02:29
  • ini_set('display_errors', true) works, and i found where my error is. Thanks. but the updated version i aded is not completely showing here. – vivim Dec 14 '16 at 03:02
  • well, so, that page is your `project.php`..? if so, `$_GET['thb_id']` should be `$_GET['project_id']` as you pass in your `'.../project.php?project_id=' . ($page+1) ...` further read, [w3schools](http://www.w3schools.com/php/php_forms.asp) – Bagus Tesa Dec 14 '16 at 03:39

1 Answers1

-1

Looks like you have an extra } at the end

Ray
  • 723
  • 7
  • 21