Getting 500 internal server error - php file accesing mysql

Hi,
I searched about this error on many forums, and nobody knows precisely how to fix it.

I have this error on my php file “Cautare.php” ( the translation is Search.php ) on my website cristishor, which it accesing a database with the same name .

I reviewed my php file multiple times, and still I don’t know what I miss.
Some advice please.

And one more thing : I seen a weird folder like “MM_something” on my subdomain cristishor root folder, and I deleted it , because I thought it was a virus, that it put it inside. :wink:

Well, the first step is to try if you can get an error message from PHP, so make sure all errors are reported and shown. You can do this by adding the following lines to the beginning of your file:

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

If you’re lucky, this should show you the error message encountered by PHP and the line it happens on, which should make fixing it a lot easier.

I put it, and nothing happen. The same error appear.

@Cristif92 said:
I put it, and nothing happen. The same error appear.

Well, I’m sorry to say that’s about as far as I can help you without knowing which page or script is broken.

Some good news. :slight_smile: I manage to find the mistake, and it display this errors :

Notice: Undefined index: q in /home/dezile/public_html/cristishor.is-great.net/Cautare.php on line 6

Warning: mysqli_connect(): (HY000/2003): Can't connect to MySQL server on 'sql205.freecluster.eu' (110) in /home/dezile/public_html/cristishor.is-great.net/Cautare.php on line 12

Thanks ! :smile:

The second error I will remake the database, and take the information of login, so It’s easy way.
But I don’t know how to declare a variable.
The most probably, I will try
varchar q;

This reply it’s as a good news that your code you provide works, and as a thank you :smile:

@Cristif92 said:
Some good news. :slight_smile: I manage to find the mistake, and it display this errors :

Notice: Undefined index: q in /home/dezile/public_html/cristishor.is-great.net/Cautare.php on line 6

Warning: mysqli_connect(): (HY000/2003): Can't connect to MySQL server on 'sql205.freecluster.eu' (110) in /home/dezile/public_html/cristishor.is-great.net/Cautare.php on line 12

Thanks ! :smile:

The second error I will remake the database, and take the information of login, so It’s easy way.
But I don’t know how to declare a variable.
The most probably, I will try
varchar q;

This reply it’s as a good news that your code you provide works, and as a thank you :smile:

“Undefined index” does not apply to defined variables, it has to do with array keys. This error is returned if $array['q'] is not defined (or, more likely $_GET['q']). You can’t really “define” the variable, but you can check if it exists with isset($array['q']) or simply assign a value to it.