Syntax when forming an array. server response 500

Hello. I’m sitting on the 5th day (excluding weekends) with a trouble. Made in php something like a vip-ads module on the site.
The module works (at first there was a jQuery rotator, then it dropped to the random output of the 1st ad) with the module enabled, the site is displayed properly BUT! the server response comes not 200, but 500 O_o ​​Came to the conclusion that something unknowingly screwed up. Please correct it as it should be.

$db = mysql_connect("","",""); //        
mysql_select_db("",$db); //   
mysql_query('SET NAMES utf8');
$result = mysql_query("SELECT LEFT(text, 200) as text, img, contact, sort, what FROM vips order by rand() limit 1",$db); //       table
if(!$result) //    
echo "<p>      . ,   : [email protected] <br> :</p>";
exit(mysql_error()); //  
if (mysql_num_rows($result) > 0) //  
$array = mysql_fetch_array($result); //   
echo "<li onclick=\"facechange('.blya');$('#pikame').PikaChoose({startOn:".$array['sort'].", autoPlay:false, showCaption:true});hider1('.hiderrr'); return false;\">
<div class=ttop valign=bottom></div>
<img border=0 align=left hspace=13 src=".$array['img']." width=100>
<h3 class=radv>".$array['what']."</h3>
<div class=bott><span class=contactt valign=bottom>".$array['contact']."</span>&nbsp;&nbsp;&nbsp;</div>
while($array = mysql_fetch_array($result));
else {echo "    .    ";
exit(); //   



<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
#     (  )
<IfModule mod_expires.c>
ExpiresActive On
#         ( ).
ExpiresDefault A1209600
#   ,  
ExpiresByType text/html A1

Answer 1, authority 100%

I copied this code for myself, corrected it for my table, HTTP/1.1 200 OK.

There is only one thing to say, the code is clumsy. It is not clear why there are so many exits. And why are you using a loop? If you receive only one line of data in the request, and judging by your comment, display only one as well.

I think that if you get a 500 error in the responses, then most likely there is an error in the apache/php configuration.

Answer 2

we should look at the Apache logs (if it is installed) – everything is displayed there: the response is 500, the reason is such and such

UPD:if the 500 response is an INTERNAL server error, not a programming error.

Answer 3

Missed “<?” at the beginning, unless, of course, you accidentally missed it when copying the code here.

Try commenting out exit(); the interpreter should print its error and indicate exactly where the error was.