Error 500 Internal Server Error

Asked

Viewed 2,136 times

1

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

The block that receives this query on the map_page.php page (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;
    }
}

http://pastebin.com/A72pypih

  • Place this code at the beginning of your php file to verify the error and refer to your browser URL, then edit your question with overro: ini_set('display_errors', 'On'); error_reporting(E_ALL);

  • Nothing different, just to remember the page normally loads the part, only with the query happens this.

  • Go to the url directly in the browser map_page.php? [PARAMETROS] and see the error that will be shown. Post the error if you cannot identify the problem..

  • @Juniorct when you have snippets of code to show, do not use external links like Pastebin, but post the code here so that the question is not invalidated if the link is lost.

  • On which line is the error?

3 answers

4


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

A common cause is some error in htaccess.

To verify the error, read the server error log.

Remember that this type of error is not accessible by PHP, so you won’t be able to read the log details by activating the error display in PHP.

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

1

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

Second, you will only receive 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 errors add the lines below at the top of your PHP file:

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

Additionally, you can enable errors in all PHP scripts by changing their php.ini, to this end, it is sufficient to amend the display_errors as shown below:

error_reporting  =  E_ALL
display_errors = On

In your code there are some problems, which, if I may, I’d like to warn you.

  • Never use the @ to suppress errors, this is not only a bad practice but slows down your code.
  • Don’t mix HTML and PHP, I know you’re getting started, but it’s good to get started right. Search for MVC or some design standard that removes the coupling between vision and its control.

-4

Dude. The best thing you have to do is create a script to make the mistakes right away. So you’ll always know what’s going on. Study about the functions set_error_handler, mkdir e fwrite and about the class SplFileObject .

Browser other questions tagged

You are not signed in. Login or sign up in order to post.