Jump to content

Recommended Posts

Whenever I hit submit I get an internal server error. Here is the code:

<?php $modsToBeChecked = str_replace(
"\r",
"\n",
str_replace( "\r\n", "\n", $_POST[ 'modsToBeChecked' ] )
);
$modsToBeChecked = explode( "\n", $modsToBeChecked );


var_dump( $modsToBeChecked );?>

$modsToBeChecked is passed in from a textarea form. It is suppose to treat each line in the textbox as one element of the array. Here is the form code in case you need it:

<form  action=""><textarea name="modsToBeChecked" rows="25" cols="50"></textarea>
<input type="submit">
</form>
Link to comment
https://forums.phpfreaks.com/topic/292965-getting-internal-server-error-on-submit/
Share on other sites

 

Whenever I hit submit I get an internal server error.

Check your severs error logs to see why you are getting that error. Or add the following after the opening PHP tag line to see the error message(s) in the browser.

ini_set('display_errors', 1);
error_reporting(E_ALL);

Depends, are you submitting the form using GET or POST? Your earlier code indicated $_POST but now you are trying to access $_GET

Sorry about the confusion. In the original post I have the form using get yet the PHP looking for post. It is using get.

 

 

Before using $_POST[ 'modsToBeChecked' ] you need check if this element is exists

if(isset($_POST[ 'modsToBeChecked' ])) {     //Element exists, you may use it }

Now my code is:

 

if(isset($_GET[ 'modsToBeChecked' ])) {
$modsToBeChecked = str_replace(
"\r",
"\n",
str_replace( "\r\n", "\n", $_GET[ 'modsToBeChecked' ] )
);
$modsToBeChecked = explode( "\n", $modsToBeChecked );
 
var_dump( $modsToBeChecked );
}
 
 
I'm not getting any errors generated by php yet still getting a  internal server error!
if(isset($_GET['modsToBeChecked'])) {
$modsToBeChecked = preg_replace(array("/\r\n+/", "/\r+/", "/\n+/"), "/n",trim($_GET['modsToBeChecked']));
$modsToBeChecked = explode("/n", $modsToBeChecked);

var_dump($modsToBeChecked);
}

You can probably improve it more depending on spaces in mod names, wasn't sure what your data was

I would first check the error logs,as was mentioned earlier, and then work on tackling that php page.

I don't see an action url set in your form, which means by default it just submits to the same page. Make sure they are otherwise you need to set the action attribute in your form to where the script is located.

Then you will need to look at your servers error logs

As already stated there are none.

 

if(isset($_GET['modsToBeChecked'])) { $modsToBeChecked = preg_replace(array("/\r\n+/", "/\r+/", "/\n+/"), "/n",trim($_GET['modsToBeChecked'])); $modsToBeChecked = explode("/n", $modsToBeChecked); var_dump($modsToBeChecked); }

You can probably improve it more depending on spaces in mod names, wasn't sure what your data was

 

Ya mod names can have spaces hence why I use each line as an element.

 

I would first check the error logs,as was mentioned earlier, and then work on tackling that php page.

I don't see an action url set in your form, which means by default it just submits to the same page. Make sure they are otherwise you need to set the action attribute in your form to where the script is located.

The php script is on the same page hence why there is no action attribute.

could you post a REAL example of the content of modsToBeChecked ?

 

An Internal Server error normally is logged... are you sure that you are looking the right logs files?

 

The last code that you posted works fine on testing, therefore seems that the POSTED code is not the issue here. Are you psoting the WHOLE code that you are using?...

Edited by mikosiko
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.