Link to home
Start Free TrialLog in
Avatar of cjtruty
cjtruty

asked on

How do I solve Error 500 problem?

I am attempting to display a simple MySQL query via PHP of a table with 5 records in it.   I consistently get an Error 500 msg whenever I try to display it as shown below:

Error Code: 0x00000000
Notification: ExecuteRequestHandler
Module: IsapiModule
Requested URL: http://localhost:80/Test.php
Physical Path: C:\inetpub\wwwroot\Test.php
Logon User: Anonymous
Logon Method: Anonymous
Failed Request Tracing Log Directory: C:\inetpub\logs\FailedReqLogFiles
Handler: PHP

The inetpub error log shows the one and only following warning message:

MODULE_SET_RESPONSE_ERROR_STATUS
Warning ModuleName="IsapiModule", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="500", HttpReason="Internal Server Error", HttpSubStatus="0", ErrorCode="The operation completed successfully. (0x0)", ConfigExceptionInfo=""

I can query this table successfully from the MySQL Administrator:

Here are the current software configuration parameters.

OS: Windows Vista
IIS: ver7
PHP: ver 5.2.5
MySQL: ver 5.0
IIS is on localhost.

I believe PHP is installed correctly because phpinfo() does display and it does show MySQL installed.
The php.ini file has the mysql info set correctly including:
- extensions enabled
- extensions directory set
- php_mysql.dll unremarked

In the databases connection module while creating the page, I can successfully test the connection to the MYSQL databases and select databases.   That's as far as I can go.

It appears to be a problem with the isapi module and I'm wondering about permissions since c:\inetpub\ and its subdirectories are currently in 'read-only' but haven't been able to change this either.

Any help would be appreciated.  Thank you....




Avatar of deepsnow2008
deepsnow2008

Hi cjtruty,

Try to change the permission from IIS manager.
Avatar of Göran Andersson
Error 500 only means that there was a problem when running the server code, it doesn't say anything at all about what the specific problem was. Don't you get any kind of error message?

> c:\inetpub\ and its subdirectories are currently in 'read-only' but haven't been able to change this either.

Don't worry about that. There is no such thing as a read-only folder. What you see in the properties for the folder is supposed to reflect the read-only state of the files in the folder, but that doesn't work very well.
In Internet Explorer, click on Options -> Advanced and make sure that the "Show Friendly HTTP messages" is unchecked. Then close your browser and open it again and execute your code. You will be able to see the line number and the statement where this error occurs.
Avatar of cjtruty

ASKER

What I originally posted was all I get in IE with the 'Show Friendly...' unchecked.  
Avatar of cjtruty

ASKER

Does this appear to be a permissions error?  A simple php page that displays the date, time does work..
It pretty much only appears to be an error, as the error message doesn't say anything at all about where the error occurs, or why.

Have you tries the exact same query that you have in the code in the MySQL Administractor?

What does your code look like?
Avatar of cjtruty

ASKER

The query works fine in the  SQL Administrator.  Attached is the code from the page....  It's a simple query created in Dreamweaver.
<?php virtual('/Connections/Scores.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
 
mysql_select_db($database_Scores, $Scores);
$query_Recordset1 = "SELECT * FROM main";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $Scores) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
 
if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
 
<body>
<table border="1">
  <tr>
    <td>LastName</td>
    <td>Birthday</td>
    <td>SSN</td>
    <td>Score</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_Recordset1['LastName']; ?></td>
      <td><?php echo $row_Recordset1['Birthday']; ?></td>
      <td><?php echo $row_Recordset1['SSN']; ?></td>
      <td><?php echo $row_Recordset1['Score']; ?></td>
    </tr>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Open in new window

Avatar of cjtruty

ASKER

After I noticed the code, I saw that the header information for the page was below the php code.  I think this may be along the right track.   I need to figure out where the php code should be in the page.  I've tried in the body and have gotten rid of the Error 500 but now just get a blank page.  Recreating the page from scratch just puts the php code in the same place...above the <head></head>.
> I saw that the header information for the page was below the php code.

That's no problem as long as you don't do any output in that part of the code.

Comment out most of the php code until you get it to run, then you can uncomment it piece by piece until you find what it is that breaks.
Avatar of cjtruty

ASKER

Thanks for the reminder of how to trace error lines.  The line that generates the error msg is the 3rd line of the code:

if (!function exists("GetSQLValueString"))  {

Syntax wise, parentheses and brackets are equal


<?php virtual('/Connections/Scores.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 
mysql_select_db($database_Scores, $Scores);
$query_Recordset1 = "SELECT * FROM main";
$Recordset1 = mysql_query($query_Recordset1, $Scores) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

Open in new window

I can't see that you are using the function GetSQLValueString anywhere in your code. What if you just comment out that part?
Avatar of cjtruty

ASKER

It doesn't seem to make a difference.  As long as I have a recordset defined, whatever the default code that is added to the page with that definition causes the error.  I have a phpinfo() line that works fine without the recordset defintion but is never executed with the recordset defined.  The recordset definition itself (when  defining and testing) works fine, but not the page of code.  Could PHP not be handling the MySQL call correctly when trying to display the page?

What's interesting is that the error message that is returned in the inetpub fail logs is a code '0x0' that is defined  as 'ErrorCode="The operation completed successfully. (0x0)",   Huh???
Avatar of cjtruty

ASKER

There are three sections of php code in the page.   I have removed various combinations of the three sections to isolate the section and even if I leave only the single line <?php virtual('/Connections/Scores.php'); ?> which I assume just defines the connection, causes the page to error.  

I'm grasping at straws here but I have noticed when I test the connection, it takes nearly 10-15 secs for the data to display which seems much slower than my old XP machine.  Could IIS be timing out when data is not returned promptly??  Any ways of testing any of these theories or finding more detailed info on the errors?  Some sort of PHP or IIS trace?

Thanks again,
> What's interesting is that the error message that is returned in the inetpub fail logs is a
> code '0x0' that is defined  as 'ErrorCode="The operation completed successfully. (0x0)"

That's because it's a server code error, not an http error. The response is a valid http response, but it contains a page that describes the server code error.


Do you have the file C:\inetpub\wwwroot\Connections\Scores.php that the code is trying to include? What does it contain?
Avatar of cjtruty

ASKER

I have included all the code in earlier postings.  Dont' want to make this posting any longer than necessary.  You told me earlier to begin commenting out the code to narrow down the line but any of the php lines generate the error.  

Again, a page with just the phpinfo() command is fine, but it's when the MySQL recordset is established that the error occurs with the code that the recordset establishment generates.  Nothing needs to even be displayed on the page.  Just setting up the connection causes the display to fail.

Thanks again,
> I have included all the code in earlier postings.

In that case the error is that you are trying to include a page that doesn't exist. You need the file Scores.php, as it contains the code that does the database connection.
Avatar of cjtruty

ASKER

Didn't even know about this file.    Displaying this php code all by itself in a browser, does not generate the error so I assume that it's connecting to the MySQL database OK, correct?
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_Scores = "localhost";
$database_Scores = "scores";
$username_Scores = "dbuser";
$password_Scores = "abcdef";
$Scores = mysql_pconnect($hostname_Scores, $username_Scores, $password_Scores) or trigger_error(mysql_error(),E_USER_ERROR); 
?>

Open in new window

Avatar of cjtruty

ASKER

I've attached the portion of the IIS trace log that is the 5 steps prior to the error.  Does this help with anything other than the isapi module doesn't like something??

50. n n i  ISAPI_START  00:27:31.586
51. n n i  CALL_ISAPI_EXTENSION DllName="C:\PHP\php5isapi.dll" 00:27:31.586
52. n n —  NOTIFY_MODULE_START ModuleName="IsapiFilterModule", Notification="MAP_PATH", fIsPostNotification="false", fIsCompletion="false" 00:27:31.586
53. n n —  NOTIFY_MODULE_END ModuleName="IsapiFilterModule", Notification="MAP_PATH", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 00:27:31.586
54. n n r  MODULE_SET_RESPONSE_ERROR_STATUS
Warning ModuleName="IsapiModule", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="500", HttpReason="Internal Server Error", HttpSubStatus="0", ErrorCode="The operation completed successfully. (0x0)", ConfigExceptionInfo=""
ASKER CERTIFIED SOLUTION
Avatar of Göran Andersson
Göran Andersson
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cjtruty

ASKER

THANK YOU!!!!  Changing the 'virtual' to 'include' eliminated the error so that was a step in the right direction however I then couldn't display anything on the page...it would be blank no matter what I put on it.  Knowing the problem was with that line of code, I just replaced the line of code with the  'include' statement with the code from the Scores.php file and everything worked.  

Would this problem with 'includes' indicate a problem with php or how IIS handles php pages??  Thanks again!!!!!

Avatar of cjtruty

ASKER

Thank you again...I've spent nearly four weeks on trying to figure this one out.
Avatar of cjtruty

ASKER

Playing with the syntax, I finally got the line to work correctly....Here's the line that now works....

<?php include 'Connections/Scores.php';?>

Thanks again