Jump to content

[SOLVED] Stumped - 500 error


sawade

Recommended Posts

Hello all.  Well I am stumped.  Profoundly stumped.  I took a current php script I wrote previously and revamped it.  Using a few new functions that hadn't been used in the first script.  I can view my first script fine on the internet, however when I try to debug/test this new scipt my server gives me a 500 error.  I have checked my php.ini and there is nothing in it that I can see that should be causing a conflict. 

 

So... I am asking for help.  Below is the new code...

 

<?php

  ini_set("display_errors", "1");
  error_reporting(E_ALL);
  //error_reporting(E_ALL ^ E_NOTICE);

  session_start();
  setlocale(LC_ALL, '');
?>

HTML head tag... etc...

if (isset($_POST['submit'])) {
  
$error = '';//initialize $error to blank
... lists additional variables

Here is an example of the strings I added...

if (empty($first_name) && empty($last_name)) { // IF first and last are empty - REQUIRED FIELD
	$error .= 'Please input your FIRST NAME and LAST NAME.<br />';
      	$output_form = true;
    }

    if (empty($first_name)) { // IF first only is empty - REQUIRED FIELD
	$error .= 'Please input your FIRST NAME.<br />';
      	$output_form = true;
    }
else {
        if (!empty($first_name) && strlen($first_name) < 2 || strlen($first_name) > 30) { // IF first is not empty and is not between 2 and 30 characters
		$error .= 'FIRST NAME must be between 2 and 30 characters.<br />';
		$output_form = true;
	}
}
else {
        if (!empty($first_name) && !ctype_alpha($first_name)) { // IF first is not empty and contains illegal characters
		$error .= 'FIRST NAME contains illegal characters.<br />';
		$output_form = true;
	}
}

etc... several hundred lines of code in between...

}	
  else {
    $output_form = true;
  }	

if ($error=='') { //IF NO errors process form

...email address validator
...captcah validator
... if all clear runs the email script
...echo confirmation


}
    else{
       echo '<p class="error">'$error'</p>';// List errors
    }

}
else {    
	// Email not valid
	$error .= 'Please input a VALID EMAIL ADDRESS.<br />';
	$output_form = true;
	}
}
else {
	// CAPTCHA not valid
	$error .= 'Please enter the VERIFICATION PASS-PHRASE exactly as shown.<br />';
	$output_form = true;
	}

}

  if ($output_form == true) {
?>

<div id="form">

  <form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
  
<p id="required">*Indicates a required field</p>

Additional HTML code for form.

Link to comment
Share on other sites

Whenever i get those, it's a problem with the server configuration.

 

best bet is to comment out blocks of code until it works and you know what's causing the problem

 

I am doing just that.  I get the error as soon as the code for the ctype_*() functions are input.  My server is running the most up-to-date php version... why could this be happening??

 

Thanks.

Link to comment
Share on other sites

You are likely getting a fatal parse error. Putting the two lines -  ini_set("display_errors", "1");/ error_reporting(E_ALL); in your script won't help display fatal parse errors. Those lines are only used/suggested for in a script file when it appears that the code is actually being executed (parse errors prevent the code from even being executed.)

 

Set the display_errors/error_reporting settings in your php.ini in order to see all the php detected errors. Stop and start your web server to get any change made to php.ini to take effect.

Link to comment
Share on other sites

You are likely getting a fatal parse error. Putting the two lines -  ini_set("display_errors", "1");/ error_reporting(E_ALL); in your script won't help display fatal parse errors. Those lines are only used/suggested for in a script file when it appears that the code is actually being executed (parse errors prevent the code from even being executed.)

 

Set the display_errors/error_reporting settings in your php.ini in order to see all the php detected errors. Stop and start your web server to get any change made to php.ini to take effect.

 

Those lines are only in the file during testing, then are removed.  I have my php.ini file set up for logging errors not showing them.  And my error logs are completely empty.  Nothing is being passed into them.

Link to comment
Share on other sites

And you have confirmed the actual runtime values of the error_reporting and log_errors settings using a phpinfo() statement?

 

Beyond that, you would need to post actual code that produces the symptom.

 

Yes.

 

if (!empty($first_name) && !ctype_alpha($first_name)) { 

 

Any use of the ctype_*() function creates the 500 error.  But does not send an error to the php log or any of my other error logs.  All I get is the internal server error.  If I remove the ctype the script runs like clockwork.

 

I have sent an email to my host server, thinking maybe with their master config. they do not allow this function.  Should this prove to be true... anything ideas of an alternate function to use?

Link to comment
Share on other sites

LOL You know.  It never ceases to amaze me how something so small can totally mess up the whole thing.

 

Chalk it up as a Homer Simpson... D'ohhh!!! ::)

 

After hours of brooding... here was issue...

 

if (empty($first_name) && empty($last_name)) { // IF first and last are empty - REQUIRED FIELD
	$error .= 'Please input your FIRST NAME and LAST NAME.<br />';
      	$output_form = true;
    }

    if (empty($first_name)) { // IF first only is empty - REQUIRED FIELD
	$error .= 'Please input your FIRST NAME.<br />';
      	$output_form = true;
    }
else {
        if (!empty($first_name) && strlen($first_name) < 2 || strlen($first_name) > 30) { // IF first is not empty and is not between 2 and 30 characters
		$error .= 'FIRST NAME must be between 2 and 30 characters.<br />';
		$output_form = true;
	}
}
else {
        if (!empty($first_name) && !ctype_alpha($first_name)) { // IF first is not empty and contains illegal characters
		$error .= 'FIRST NAME contains illegal characters.<br />';
		$output_form = true;
	}
}

 

I was thinking it was the ctype, but really it's the if else statements.  They should be as follows...

 

if (empty($first_name) && empty($last_name)) { // IF first and last are empty - REQUIRED FIELD
	$error .= 'Please input your FIRST NAME and LAST NAME.<br />';
      	$output_form = true;
    }

if (empty($first_name)) { // IF first only is empty - REQUIRED FIELD
	$error .= 'Please input your FIRST NAME.<br />';
      	$output_form = true;
    }

if (!empty($first_name) && strlen($first_name) < 2 || strlen($first_name) > 30) { // IF first is not empty and is not between 2 and 30 characters
	$error .= 'FIRST NAME must be between 2 and 30 characters.<br />';
	$output_form = true;
}

if (!empty($first_name) && !ctype_alpha($first_name)) { // IF first is not empty and contains illegal characters
	$error .= 'FIRST NAME contains illegal characters.<br />';
	$output_form = true;
}

 

Well that's what I get for trying to get it scripted out too quickly.  Better to take your time and do it right the first time. 

 

LOL  Thanks all for the assistance.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.