Error 500 Internal Server Error [closed]

1

I'm trying to do a POST query with jquery on my website online but I get the error 500 Internal Server Error, this and the query (jquery): $('#background').load('map_page.php', {'a':'see_member', 'id': id});

The block that receives this query in the page map_page.php (php):

if($a == 'see_member') {
    $id = @$_POST['id'];
    if($id) {
        $q = $dbAgent -> query("select * from map where id=$id");
        $a = $dbAgent -> fetch($q);
        $logo = $a['logo'];
        $title = $a['name'];
        $desc = $a['description'];
        $address = $a['address'];
        echo "
            <a href='#' onclick='closeCompany($id)'>
                <img src='media/cancel.png' id='close'>
            </a>
            <img src='$logo' id='prof'>
        ";

        $r1 = $a['rate_1']; $r2 = $a['rate_2'];
        $r3 = $a['rate_3']; $r4 = $a['rate_4'];
        $r5 = $a['rate_5'];
        $allStars = array(
            0=>0, 1=>$r1, 2=>$r2, 3=>$r3,
            4=>$r4, 5=>$r5
        );
        $biggestStar = 0;
        for($i=1;$i<count($allStars);$i++) {
            $st = $allStars[$i];
            if($st > $allStars[$biggestStar]) {
                $biggestStar = $i;
            }
        }
        $NUM_STARS = 5;
        if(!$clientTools -> rated($id)) {
            echo "<span class='rate_stars' id='rate_stars' onmouseenter='setVoteAble($NUM_STARS,$id)'
                >";
        }
        else {
            echo "<span class='rate_stars' id='rate_stars'>";
        }
        for($i=1;$i<count($allStars);$i++) {
            if(($allStars[$i] < $allStars[$biggestStar] and $i < $biggestStar) or $i == $biggestStar) {
                echo "<img class='rate_star' id='rate_star_$i' src='/media/star_fill.gif'>";
            }
            else {
                echo "<img class='rate_star' id='rate_star_$i' src='/media/star_bg.gif'>";
            }
        }
        $numVotes = $allStars[$biggestStar];
        echo "<br><span id='numVotesStars'>$biggestStar estrelas. ($numVotes votos)</span>";
        echo "</span>";

        echo "
            <div class='p_map'>
            </div>
        ";

        echo "
            <div id='cont'>
                <center><text id='header'>$title</text></center>
                <br><br>
                <text id='content'>$desc</text>
                <br><br>
                <text id='content' style='font-weight: bold'>$address</text>
            </div>
        ";
        return;
    }
}

link

    
asked by anonymous 10.12.2015 / 23:18

3 answers

4

The message "500 Internal Server Error" usually indicates error coming from the web server. Usually Apache.

A common cause is some htaccess error.

To clear the error, read the server's error log.

Note that this type of error is not accessible by PHP, so you will not be able to read the log details by enabling the display of errors in PHP.

However, not always the error is webserver, because it is possible to configure the environment so that errors of PHP or another module, for example, are treated by the webserver with status 500.

    
11.12.2015 / 11:17
0

First, if this code in the pastbin is your complete code, PHP's opening and closing tags are missing. <?php ?> and there is a return; outside of a function. And then on line 3 the variable $ a is being used in a if ($a == 'see_member'){} parison comparison but it is not instantiated.

Second, you will only receive the errors in your program if you tell PHP that you would like to see them. This prevents PHP from displaying errors on a production system, causing user discomfort and system insecurity. To enable the errors add the following lines at the top of your PHP file:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

In addition, you can enable errors in all PHP scripts by changing your php.ini , to do this simply change the display_errors directive as shown below:

error_reporting  =  E_ALL
display_errors = On

In your code there are some problems, which if you allow me, I would like to alert you.

  • Never use @ to suppress errors, this is not just a bad practice, it slows down your code.
  • Do not mix HTML and PHP, I know you're starting, but it's good to start right now. Search for MVC or some design pattern which removes the coupling between the view and its control.
11.12.2015 / 01:45
-4

Dude. The best thing you have to do is to create a script to make mistakes soon. So you will always know what is happening. Study the functions set_error_handler, mkdir e fwrite and the SplFileObject class.

    
11.12.2015 / 02:19