Apache error.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
brewmiser
Forum Commoner
Posts: 74
Joined: Mon Aug 18, 2003 12:50 pm
Location: Dallas, TEXAS

Apache error.

Post by brewmiser »

Why am I getting an error from my Apache server that looks like this:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, email@company.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Apache/1.3.27 Server at http://www.somesite.com Port 80


All my webpages work....except for the following page, which is giving me the error:

Code: Select all

<?php require("../includes/dbconnect.inc"); ?>
<?php require("../includes/functions.inc"); ?>
<?php require("../includes/styles.inc"); ?>

<?php
if (isset($id_company))
{
  $company = mysql_query("SELECT * FROM company WHERE company_id = '".$id_company."'")
  	or die("<b>MySQL Error:</b> ".mysql_errno()." : ".mysql_error());
	$company_fill = mysql_fetch_array($company);
	
	//building phone numbers for display, from database 
  if (!$company_fill["phone_1"]=="")
	{
    $db_phone_number_1 = ($company_fill["phone_1"]);
    $area_code_1 = substr($db_phone_number_1, -10, 3);
	  $three_digit_1 = substr($db_phone_number_1, -7, 3);
		$four_digit_1 = substr($db_phone_number_1, -4, 4);
	}
	if (!$company_fill["phone_2"]=="")
  {
    $db_phone_number_2 = ($company_fill["phone_2"]);
    $area_code_2 = substr($db_phone_number_2, -10, 3);
		$three_digit_2 = substr($db_phone_number_2, -7, 3);
		$four_digit_2 = substr($db_phone_number_2, -4, 4);
	}
	if (!$company_fill["fax_1"]=="")
	{
    $db_phone_number_3 = ($company_fill["fax_1"]);
    $area_code_3 = substr($db_phone_number_3, -10, 3);
		$three_digit_3 = substr($db_phone_number_3, -7, 3);
		$four_digit_3 = substr($db_phone_number_3, -4, 4);
	}
	if (!$company_fill["fax_2"]=="")
	{
    $db_phone_number_4 = ($company_fill["fax_2"]);
    $area_code_4 = substr($db_phone_number_4, -10, 3);
		$three_digit_4 = substr($db_phone_number_4, -7, 3);
		$four_digit_4 = substr($db_phone_number_4, -4, 4);
	}
}
?>

<body>
<form method=post action="contact_inputdata.php"><b>
  <table class="main">
    <tr>
		  <td colspan=2 valign="top"><p class="title">New Company</p></td>
	  </tr>
		<tr>
		  <td align=center colspan=2><hr></td>
		</tr>
		<tr><td>
		  <table>
			  <tr>
				  <td width="33%"><p>Company Name</p></td>
					<td><p><input type="text" name="company_name" size="43" value="<?php echo $company_fill["company_name"]; ?>"></p></td>
				</tr>
				<tr>
				  <td><p>Abbreviation</p></td>
					<td><font face="Arial,Helvetica" size="2" color="Black"><input type="text" name="abbreviation" size="5" value="<?php echo $company_fill["abbreviation"]; ?>"></font></td>
				</tr>	
				<tr>
				  <td><p>Phone #1</p></td>
    			<td><p>
		    	  (<input type="text" name="phone_1a" size="3" maxlength="3" value="<?php echo $area_code_1; ?>">) - <input type="text" name="phone_1b" size="3" maxlength="3" value="<?php echo $three_digit_1; ?>"> - <input type="text" name="phone_1c" size="4" maxlength="4" value="<?php echo $four_digit_1; ?>">
			    </td>
    		</tr>
		    <tr>
		      <td><p>Phone #2</p></td>
			    <td><p>
			      (<input type="text" name="phone_2a" size="3" maxlength="3" value="<?php echo $area_code_2; ?>">) - <input type="text" name="phone_2b" size="3" maxlength="3" value="<?php echo $three_digit_2; ?>"> - <input type="text" name="phone_2c" size="4" maxlength="4" value="<?php echo $four_digit_2; ?>">
    			</td>
		    </tr>
    		<tr>
		      <td><p>FAX #1</p></td>
			    <td><p>
			      (<input type="text" name="fax_1a" size="3" maxlength="3" value="<?php echo $area_code_3; ?>">) - <input type="text" name="fax_1b" size="3" maxlength="3" value="<?php echo $three_digit_3; ?>"> - <input type="text" name="fax_1c" size="4" maxlength="4" value="<?php echo $four_digit_3; ?>">
			    </td>
		    </tr>
    		<tr>
		      <td><p>FAX #2</p></td>
    			<td><p>
		    	  (<input type="text" name="fax_2a" size="3" maxlength="3" value="<?php echo $area_code_4; ?>">) - <input type="text" name="fax_2b" size="3" maxlength="3" value="<?php echo $three_digit_4; ?>"> - <input type="text" name="fax_2c" size="4" maxlength="4" value="<?php echo $four_digit_4; ?>">
    			</td>
		    </tr>
    		<tr>
		      <td><p>Web Site</p></td>
    			<td><input type="text" name="website" size="43" value="<?php echo $company_fill["website"]; ?>"></td>
		    </tr>
				<tr>
				  <td valign="top"><p>Company Type</a></p></td>
					<td><!-- fills role information from database -->
					  <select name="role_id[]" size="10" multiple="multiple"> 
      			<?php 
	      		  $results = mysql_query("SELECT company_role_id, company_role FROM company_role_list ORDER BY company_role ASC")
				  	  or die("<b>MySQL Error 1:</b> ".mysql_errno()." : ".mysql_error());
					 
				      if (mysql_numrows($results)>0)
    			  	{
  	    			  $numrows = mysql_numrows($results);
	  		    		$x = 0;
		  			    while ($x<$numrows)
    			  		{
		    		  	  $role_array = mysql_fetch_array($results);
				    	  	$description = ($role_array["company_role"]);
						      $theID = ($role_array["company_role_id"]);
      			?>
				    <option value="<?php echo $theID; ?>"><?php echo $description; ?></option>
    	  		<?php
		    	        $x++;
			  		    }
				      }
						?>
						</selected>
					</td>
				</tr>
    		<tr>
		      <td><p>Remarks</p></td>
    			<td><textarea name="company_remarks" rows="5" cols="26"></textarea></td>
		    </tr>
			</table>
		</td></tr>
		<tr>
		  <td align=center colspan=2><hr></td>
		</tr>
		<tr>
		  <td colspan=2>
			  <input type="submit" value="Submit data">
				<input type="hidden" name="new_contact">
			</td>
		</tr>
  </table></b>
</form>
</body>
Any clues??

HELP !!
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

ummm.. hmmmm

is this the only php page?

why do you go in and out of php?

i ask because this seems like it'd be better to me (uses heredoc format... if you don't want heredoc, then think about it for the begining, there's no point in going in and out of php there)

Code: Select all

<?php
require("../includes/dbconnect.inc");
require("../includes/functions.inc");
require("../includes/styles.inc");

if (isset($id_company)) 
{ 
  $company = mysql_query("SELECT * FROM company WHERE company_id = '".$id_company."'") 
     or die("<b>MySQL Error:</b> ".mysql_errno()." : ".mysql_error()); 
   $company_fill = mysql_fetch_array($company); 
    
   //building phone numbers for display, from database 
  if (!$company_fill["phone_1"]=="") 
   { 
    $db_phone_number_1 = ($company_fill["phone_1"]); 
    $area_code_1 = substr($db_phone_number_1, -10, 3); 
     $three_digit_1 = substr($db_phone_number_1, -7, 3); 
      $four_digit_1 = substr($db_phone_number_1, -4, 4); 
   } 
   if (!$company_fill["phone_2"]=="") 
  { 
    $db_phone_number_2 = ($company_fill["phone_2"]); 
    $area_code_2 = substr($db_phone_number_2, -10, 3); 
      $three_digit_2 = substr($db_phone_number_2, -7, 3); 
      $four_digit_2 = substr($db_phone_number_2, -4, 4); 
   } 
   if (!$company_fill["fax_1"]=="") 
   { 
    $db_phone_number_3 = ($company_fill["fax_1"]); 
    $area_code_3 = substr($db_phone_number_3, -10, 3); 
      $three_digit_3 = substr($db_phone_number_3, -7, 3); 
      $four_digit_3 = substr($db_phone_number_3, -4, 4); 
   } 
   if (!$company_fill["fax_2"]=="") 
   { 
    $db_phone_number_4 = ($company_fill["fax_2"]); 
    $area_code_4 = substr($db_phone_number_4, -10, 3); 
      $three_digit_4 = substr($db_phone_number_4, -7, 3); 
      $four_digit_4 = substr($db_phone_number_4, -4, 4); 
   } 
} 
echo <<<END 

<body> 
<form method=post action="contact_inputdata.php"><b> 
  <table class="main"> 
    <tr> 
        <td colspan=2 valign="top"><p class="title">New Company</p></td> 
     </tr> 
      <tr> 
        <td align=center colspan=2><hr></td> 
      </tr> 
      <tr><td> 
        <table> 
           <tr> 
              <td width="33%"><p>Company Name</p></td> 
               <td><p><input type="text" name="company_name" size="43" value="$company_fill["company_name"]"></p></td> 
            </tr> 
            <tr> 
              <td><p>Abbreviation</p></td> 
               <td><font face="Arial,Helvetica" size="2" color="Black"><input type="text" name="abbreviation" size="5" value="$company_fill["abbreviation"]"></font></td> 
            </tr>    
            <tr> 
              <td><p>Phone #1</p></td> 
             <td><p> 
               (<input type="text" name="phone_1a" size="3" maxlength="3" value="$area_code_1">) - <input type="text" name="phone_1b" size="3" maxlength="3" value="$three_digit_1"> - <input type="text" name="phone_1c" size="4" maxlength="4" value="$four_digit_1"> 
             </td> 
          </tr> 
          <tr> 
            <td><p>Phone #2</p></td> 
<!--
shortened since i think it's enough to demo how it'd work and don't feel like going through the entire thing
-->
 <td colspan=2> 
           <input type="submit" value="Submit data"> 
            <input type="hidden" name="new_contact"> 
         </td> 
      </tr> 
  </table></b> 
</form> 
</body> 
END;
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Just a note of thoughts...

Code: Select all

$company_fill["company_name"]
// could be rewritten as...
$company_fill['company_name']
// ... to pass some problems, present or in the future
Is error reporting bumped up to max?
Bizwala
Forum Newbie
Posts: 12
Joined: Tue Sep 09, 2003 12:10 pm
Location: Las Vegas, Nevada

Post by Bizwala »

The server has encountered an error...
There are multiple reasons why this would happen.

The permissions on the script are wrong, and tons more..

I suggest looking at your access.log to see what it is. You'll find the answer there. If you don't have access to the directory where the logs are, contact your webmaster and have them send you the tail of the log after they try to load this page.

Lani
User avatar
brewmiser
Forum Commoner
Posts: 74
Joined: Mon Aug 18, 2003 12:50 pm
Location: Dallas, TEXAS

Post by brewmiser »

is this the only php page?

why do you go in and out of php?
No this is not the only page, there are many more that work just fine.
If there is a better way to write this, that would be great. I am new at php and programming altogther, so if there is a better why I will do it. Is the way that you did it faster or better in some way?
Is error reporting bumped up to max?
Yes, I believe it is.
I suggest looking at your access.log to see what it is.
The log says the following:
Error log reads - [Thu Sep 11 20:46:14 2003] [error] [client 192.168.1.101] Premature end of script headers: c:/php/php.exe

Access log reads - 192.168.1.101 - - [11/Sep/2003:20:46:14 -0500] "GET /bce-v032/contacts/company_new.php HTTP/1.1" 500 608
192.168.1.101 - - [12/Sep/2003:06:29:26 -0500] "OPTIONS / HTTP/1.1" 200 -
192.168.1.101 - - [12/Sep/2003:06:29:26 -0500] "PROPFIND /HTDOCS HTTP/1.1" 404 284


I have a linux server at the office that has no problems with this. My win2000 server at home is what is giving me the error!!!
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

in that case, if the script runs fine on linux, the issue is windows. you're doing fosomething that's ok on linux but not windows.

since your deployment invironment is linux, you should get a linux development environment.

if you have but one machine, you're about to go make a network at your home. get a new machine, buy red hat 9 server edition. go into install options, you can install apache, php and mysql as well as ssl and have a development environment that mimics your deployment environment.


i don'tknow if it's true, but i've seen otheron here say that heredocs are better than going in an out of php. that it's fater performance, so you might wanna look at how i changed it and think of doing that.


it's especially pertinent ot the begining. there is NO reason to leave php to give each include, session.start(), etc it's own <?php ?> section
User avatar
brewmiser
Forum Commoner
Posts: 74
Joined: Mon Aug 18, 2003 12:50 pm
Location: Dallas, TEXAS

Post by brewmiser »

Just to let everyone know, I fixed my problem. I upgraded to php version 4.3.3. on my windows 2000 box.

It immediatly fixed the problem and seems to work fine now.

Thanks for your help guys! :D
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

it's still a good idea to move to a linux or unix server since your deployment is posix
User avatar
brewmiser
Forum Commoner
Posts: 74
Joined: Mon Aug 18, 2003 12:50 pm
Location: Dallas, TEXAS

Post by brewmiser »

It was just easier at the time because I already had a win2000 box setup and ready to go.....but I think that I will change over to RedHat 9!! 8)
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

it may seem easier,. but then you have os specific quirks you have to worry about.

RH9 installer... go into the server side select mode.
you can pick which packages to use... that was you get php and mysql.

i know the ones that are in there because i did that.
mysql is 11.18 dist 3.23.56
php is 4.2.2
apache is 2.0.40
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

earlier in this post i saw that ppl here used array variables, remember, that when u use those in string, whether heredoc or not, u have to write it in this format: {$array['key']} NOT $array['key']
the curly braces should be around the variable so it won't confuse when parsing the string.
if you don't do this, then $array is probably going to be printed.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

that explains something... i was told i should have $_SERVER[PHP_SELF] as $_SERVER['PHP_SELF'] but the second one causes t string errors in heredodcs and the first works.
that would be why.
i use that enough i was thinking of making a variable in my includes to use it as the second.

guess i don't need to since i now know WHY it was erroring.
User avatar
brewmiser
Forum Commoner
Posts: 74
Joined: Mon Aug 18, 2003 12:50 pm
Location: Dallas, TEXAS

Post by brewmiser »

thanks Cruzado, i did not know this and have seen it both ways. I just never knew which way was the correct one.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Cruzado_Mainfrm wrote:if you don't do this, then $array is probably going to be printed.
Have in mind tho, that if you use this in a query to a database, the following will work...

Code: Select all

"select field from table where id = '$_POST&#1111;foo]'"
So it's only heredoc that has this odd (?) behaviour.

Never
User avatar
brewmiser
Forum Commoner
Posts: 74
Joined: Mon Aug 18, 2003 12:50 pm
Location: Dallas, TEXAS

Post by brewmiser »

can some one please give me a link to where I can read more, and understand more, about "heredoc". I never have heard that before and would like to know what it is..... :(
Post Reply