Hello. I'm sitting on the 5th day (not counting the weekend) with a trable. Made on php something like a module of VIP ads on the site. The module is working (at first there was a rotator on jquery, then it went down to the random output of the 1st ad) with the included module the site is displayed correctly BUT! the server's answer comes not 200, but 500 O_o. He came to the conclusion that something in ignorance nakosyachil. Please correct this for how it should be correct.

$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>Запрос выборки из базы данных не прошел. Напишите, об этом администрацию: mail@life-prog.ru. <br>Код ошибки:</p>"; exit(mysql_error()); //печатание кода ошибки } if (mysql_num_rows($result) > 0) //если выборка произошла { $array = mysql_fetch_array($result); //перекидываем выборку в массив do { 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> <p>".$array['text']."</p><br> <div class=bott><span class=contactt valign=bottom>".$array['contact']."</span>&nbsp;&nbsp;&nbsp;</div> </li>"; } while($array = mysql_fetch_array($result)); exit(); } else {echo "Информация не может быть извлечена. В таблице нет записей"; exit(); //остановка вывода в браузер } ?> 

UPD.

.htaccess

 <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] </IfModule> # Кэширование на стороне браузера (отдаем нормальные заголовки) <IfModule mod_expires.c> # Включаем ExpiresActive On # Кэшировать браузером все файлы в течении двух недель (в секундах). ExpiresDefault A1209600 # Не кэшировать файлы, имеющие тип ExpiresByType text/html A1 </IfModule> 
  • one
    would show .htaccess .. - Ozim

3 answers 3

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

You can only say one thing, the code is clumsy. It is not clear why so much exit. And why are you using a loop? If in the request you get only one line of data and judging by your comment, also output only one.

I think that if an error 500 arrives in the responses, then most likely an error in configuring apache / php.

  • By the way, I looked at the Apache error log ... there is nothing. - Vladimir2

it would be necessary to look at the Apache logs (if it costs) - everything is displayed there: the answer is 500, the reason is such and such

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

  • FoxManiac, thanks for the advice! I don’t even know about apache. I have a dedicated server for the site. This internal error occurs only with this enabled code. It seems to me that in php.ini or somewhere else there is a restriction. I would like to simplify the code, maybe it somehow gets stuck in the loop I don’t even know = (in order to tune it worked with the current settings ... something like that - Vladimir2
  • Try the following (as I do in such cases): comment on the logical blocks of code one by one. What is the page "die off" - then the "evil" :)) Okama type razor :) - FoxManiac
  • Ok, try, thanks. Surely things are in cakephp: / - Vladimir2

In the beginning, "<?" Is skipped, unless, of course, you accidentally missed when copying the code here.

Try to replace exit (); The interpreter should display its error and indicate exactly where the error was.

  • if I missed, it would have come out as HTML, but not as an error 500 ... sort of ... - FoxManiac
  • Thank. I missed it so that the code on the site was displayed correctly. exit (); I didn’t have it before, I added it myself, I thought it would help, but it didn’t work ... I’ll try just in case - Vladimir2
  • pageranker.ru / ... There are possible options for errors. Also as an option. - Fucking Babay
  • =) I meant this site. - Vladimir2