carstorm Posted December 8, 2014 Share Posted December 8, 2014 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> Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 8, 2014 Share Posted December 8, 2014 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); Quote Link to comment Share on other sites More sharing options...
carstorm Posted December 8, 2014 Author Share Posted December 8, 2014 Ah it says "Notice: Undefined index: modsToBeChecked" line 66 which is this line str_replace( "\r\n", "\n", $_GET[ 'modsToBeChecked' ] ) Is that the wrong way to get the form data? Quote Link to comment Share on other sites More sharing options...
CroNiX Posted December 8, 2014 Share Posted December 8, 2014 Depends, are you submitting the form using GET or POST? Your earlier code indicated $_POST but now you are trying to access $_GET Quote Link to comment Share on other sites More sharing options...
WinstonLA Posted December 8, 2014 Share Posted December 8, 2014 Before using $_POST[ 'modsToBeChecked' ] you need check if this element is exists if(isset($_POST[ 'modsToBeChecked' ])) { //Element exists, you may use it } Quote Link to comment Share on other sites More sharing options...
carstorm Posted December 8, 2014 Author Share Posted December 8, 2014 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! Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 8, 2014 Share Posted December 8, 2014 still getting a internal server error! Then you will need to look at your servers error logs Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted December 8, 2014 Share Posted December 8, 2014 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 Quote Link to comment Share on other sites More sharing options...
hansford Posted December 9, 2014 Share Posted December 9, 2014 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. Quote Link to comment Share on other sites More sharing options...
carstorm Posted December 9, 2014 Author Share Posted December 9, 2014 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. Quote Link to comment Share on other sites More sharing options...
mikosiko Posted December 9, 2014 Share Posted December 9, 2014 (edited) 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 December 9, 2014 by mikosiko Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.