A solution to [500 (Internal Server Error)] where the linked page is blank in a well-understood PHP textbook

Sep 6, 2020 PHP a well-understood PHP textbook [500 (Internal Server Error)] the linked page is blank

Here's a quick summary of how to solve the error that the linked page goes blank while learning with a well-understood PHP textbook.

(This is an example of how to solve errors for beginners. Please note that it is a low level)

This time it was an error at the stage of “adding the delete function”, but I think it is an error that can occur in general (?)

[Error details] Screenshot 2020-09-06 10.45.36.png When I wrote the code to delete it and accessed the link set in the delete button, it turned white. Looking at the link

delete.php =? id = 18

Since it is, it seems that you can access the post you want to delete.

[Solution procedure] I didn’t know what was happening, so check with the developer tools Screenshot 2020-09-06 10.45.53.png

Looking at this “console” part …

Screenshot 2020-09-06 10.45.59.png

I’m getting an error.

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

When I look it up … Error on web server? I’ve come up with a lot of things like that …

[500 (Internal Server Error)]

It seems to be a pretty crisp error, and it seems difficult to identify due to various causes …

Upon further investigation, it seems that there is a code to display a more detailed error on the screen, so I wrote the following code at the beginning of delete.php.

ini_set ("display_errors", 1);
error_reporting (E_ALL);

If you describe this

<? php

ini_set ("display_errors", 1);
error_reporting (E_ALL);

session_start ();
require ('dbconnect.php');

if (isset ($ _SESSION ['id'])) {
    $ id = $ _REQUEST ['id'];

    $ messages = $ db-> prepare ('SELECT * FROM posts WHERE id =?');
    $ messages-> execute (array ($ id));
    $ message = $ messeges-> fetch ();

    if ($ message ['member_id'] == $ _SESSION ['id']) {
        $ del = $ db-> prepare ('DELETE FROM posts WHERE id =?');
        $ del-> execute (array ($ id));

header ('Location: index.php');
exit ();

Like this.

When I overwrite it and try to access the delete link again …

Screenshot 2020-09-06 11.15.04.png

Somehow an error was displayed on the screen. (Exciting)

If you ask google translate to translate, Fatal error: It seems to be fatal.


“The 14th line of delete.php is useless!” It seems that it is said.

So if you check the 14th line of delete.php ..

Screenshot 2020-09-06 11.13.03.png

Some of the messages

a → e

It was. (Is it because of you …!)

that’s all I corrected the spelling and it worked fine.

I feel that 80 to 90% of errors are misspellings. It’s the same as hitting accurately, but if you can understand the error part like this time, you can save the trouble of searching, so I want to be able to master it. Also, I felt that the error is a kind person who tells me the mistake.

The end