Server Error on first page load, reload displays correctly

Disclaimer: I don’t know a lot about PHP but I’ve been able to stumble my way through a few fixes.

I have a web site that displays car listings for a local used car dealer. It’s a very old script but it’s served us very well.
In the past week it suddenly developed a problem with the vehicle detail page. The listing page loads fine, but when you click on a vehicle for the detailed info, the page results in a Server Error 500. If you click reload/refresh the page loads fine. thanks for your help. Let me know what info to provide to facilitate this process.

If you have error reporting off in PHP it could result in the 500 status.

You can do this… create a new file called info.php and paste this

[php]<?php phpinfo(); ?>[/php]

When you load info.php you will see all the settings in your php.ini

Check to see if you have

display_errors = Off

If so, you probably have log_errors = On in which case you would look at the value of “error_log” to get the path to your error log file. Then of course you would want to check the log file to see if an error is causing the 500 status.

If you have SSH access you could do something like

tail -f /path/to/php-error.log

pages don’t suddenly break without something being done to cause it. My guess is that the host maybe upgraded their php to 5.3 or 5.4, a lot of the older functions were pretty much deleted.

based on what I have seen it’s most likely a session error. He will either need to post the code or the error message. (based on that… if he changes hosts or even upgraded PHP it could change how the code works)

Thanks for your input. Yes, I believe that the php was updated on the server and therefore broke the programming. It appears the mysql_fetch_array() extension is what’s causing errors. In looking it up, that the extension is depreciated and needs to be revised. Can I just replace the old mysql_fetch_array() with the suggested one - mysqli_fetch_array? or does it function completely different? I’m sure it can’t be as easy as adding an i.

You can convert to mysqli but you have to convert everything - not just that one function.

If you want a truly quick fix you can suppress the error using @


OR modify your php.ini to hide deprecated errors

error_reporting = E_ALL & ~E_DEPRECATED

mysql_fetch_array() wasn’t depreciated. If you’re getting an error message about that function, then chances are good that the query isn’t working for whatever reason. Turn error messages on with ini_set() and add or die(mysql_error()) at the end of the affected query to see what’s going on.

You are right richei they have not been deprecated (yet). It’s been so long since I’ve used them :slight_smile:

OP, post the exact error message or the chunk of code.

thanks for sticking with me on this. I’m not sure what to post, can I post the whole script here or somewhere? The only php errors I’m getting are with the search.php. I get a 500 error on the first execution of details.php, and on reload the page displays. can I email you the full script?

Post the search script and the form if there is one. A page not found error would suggest a problem in a path somewhere.

This is search.php


										   <form name="frmFilter" action="<?php echo $site_secure_URL;?>results.php" method="get">
										   <table width="550" border="0" style="border-collapse:collapse">
  Make <?php while($row = mysql_fetch_array($rsModel)){ ?> "><? echo $row["model"] ?> <?php } ?> Min Price 0 $5,000 $10,000 $15,000 $20,000 $25,000 $30,000 $35,000 $40,000 $45,000 $50,000 $55,000 $60,000 $65,000 $70,000 $75,000 $80,000 $85,000 $90,000 $95,000 $100,000 Min Year <?php for($yearCnt=date("Y"); $yearCnt>=date("Y")-25;$yearCnt--){ ?> <? echo $yearCnt ?> <?php } ?>   Model
																<select name="cars" class="box" style="display:none; width:150px">
																	<option value="">Model</option>
																<script type="text/javascript" language="JavaScript">
																	echo "var cars = new Array();\r\n" ;
																	while($row = mysql_fetch_array($rsCars))
																		echo "cars[cars.length]= new Array('".$row["id"]."','".str_replace("'","\'",$row["model"])."','".str_replace("'","\'",$row["type"])."',".$row["price"].");\n";
<td align="left" valign="middle"> <select name="max_price" class="box" style="width:100px">
                                                              <option value="">Max Price</option>
                                                              <option value="100000">$100,000</option>
                                                              <option value="95000">$95,000</option>
                                                              <option value="90000">$90,000</option>
                                                              <option value="85000">$85,000</option>
                                                              <option value="80000">$80,000</option>
                                                              <option value="75000">$75,000</option>
                                                              <option value="70000">$70,000</option>
                                                              <option value="65000">$65,000</option>
                                                              <option value="60000">$60,000</option>
                                                              <option value="55000">$55,000</option>
                                                              <option value="50000">$50,000</option>
                                                              <option value="45000">$45,000</option>
                                                              <option value="40000">$40,000</option>
                                                              <option value="35000">$35,000</option>
                                                              <option value="30000">$30,000</option>
                                                              <option value="25000">$25,000</option>
                                                              <option value="20000">$20,000</option>
                                                              <option value="15000">$15,000</option>
                                                              <option value="10000">$10,000</option>
                                                              <option value="5000">$5,000</option>
                                                              <option value="0">0</option>
<td align="left" valign="middle"><select name="max_year" class="box" style="width:100px">
  <option value="">Max Year</option>
  <?php for($yearCnt=date("Y"); $yearCnt>=date("Y")-25;$yearCnt--){ ?>
  <option value="<? echo $yearCnt ?>"><? echo $yearCnt ?></option>
  <?php } ?>
<td align="left" valign="middle">&nbsp;</td>
   Search Features (i.e. Leather, OnStar, Third Seat, etc.)  

I’d really like to figure out why details.php causes a 500 error on first execution.

Post it.

Also post the (exact) errors you are getting.

This is a http error:

[14/Dec/2012:17:23:06 -0700] “GET /search/details.php?id=3533 HTTP/1.1” 500 5 “” “Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 900)”

I can’t post details.php, it’s says it’s over 20000 characters.

can I post it somewhere else?

Start with the errors first so you can post just the relevant section of details.php

You posted a line from your apache log which doesn’t display any error. You need to check your PHP error log (as I mentioned in the first post)

The only php error is for search.php

These are the only php errors recorded in the log

PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in …/search.php on line 16
“” on line 60
“” on line 71

That can’t be the entire form, but in any case, before you submit anything, have a look at the html output (right click, view source). make sure all that js is being formatted right.

Since Error#500 is an “Internal Server Error”, it could be almost anything server-side.
Usually, you tell the page to display all errors and it should give you more info.
Since you stated the error was in line #16, #60 and #71, most likely that would give you a starting place.
The error you got refers to
“mysql_fetch_array(): supplied argument is not a valid MySQL result resource in”
could be just a simple query error. You should add " or die mysql_error(); " to your query command.
This will show the actual error. You should add or-dies after each of your queries to show any errors.
And, then, let us know the code for the queries and the actual errors. Error#500 is just a generic error.

Sorry I didn’t have a quick answer, but, debug, debug, debug… LOL Good luck, let us know…

Thanks for all your help. I finally tracked down the error in a statistics function of the script. I had avoided the error a few years ago by switching to one of my other hosting providers. So I guess they finally updated the PHP and it broke again. By disabling this function, it all appears to work correctly now. I went back to an old support ticket with the original author of the script who wrote me four years ago saying, “We ran across the issue you are having also. It has to do with how PHP4 is handling the date, so when a person views a vehicle, it gets an error on the initial insert because it doesn’t understand the date.” So maybe I can limp through a few more months until I find a more up to date script. Thanks again.

Sponsor our Newsletter | Privacy Policy | Terms of Service