Sedona Posted August 28, 2015 Share Posted August 28, 2015 I have an HTML form using an input box, the form calls a php form to grab the POST contents. It will save any data as long as a URL (http://) is not the first characters in the input box. Http, HTTP:, http:/ all will save fine, but http:// will cause the POST array to be nulled out. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/ Share on other sites More sharing options...
QuickOldCar Posted August 28, 2015 Share Posted August 28, 2015 Can you post your code here for us? Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519835 Share on other sites More sharing options...
Sedona Posted August 28, 2015 Author Share Posted August 28, 2015 Input form <form action="/Ads/placeAd.php" method="post" enctype="multipart/form-data" id="formAd"> Line 1: <input type="text" placeholder="Remaining Characters" autofocus style="width: 250px;" name="Line1" maxlength="28" onKeyDown="textCounter1(this.form.Line1,this.form.countDisplay1);" onKeyUp="textCounter1(this.form.Line1,this.form.countDisplay1);"/><input readonly type="text" style="width: 35px;" name="countDisplay1" size="2" maxlength="2" value="28"/><input type="checkbox" name="bold" value="1"/> <strong> Make the first line bold.</strong><br> Javascript for that input box: var maxAmount = 28; function textCounter1(textField, showCountField) { if (textField.value.length > maxAmount) { textField.value = textField.value.substring(0, maxAmount); } else { showCountField.value = maxAmount - textField.value.length; } } Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519837 Share on other sites More sharing options...
Sedona Posted August 28, 2015 Author Share Posted August 28, 2015 The php code to insert the POST data is: Database connection routine $Line1=$_POST["Line1"]; $sql = "INSERT INTO SSCAds (`Line1`) VALUES ('$Line1')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519841 Share on other sites More sharing options...
scootstah Posted August 28, 2015 Share Posted August 28, 2015 When I test your code I don't see anything weird. <?php if (!empty($_POST)) { var_dump($_POST); echo '<br /><br />>'; } ?> <script type="text/javascript"> var maxAmount = 28; function textCounter1(textField, showCountField) { if (textField.value.length > maxAmount) { textField.value = textField.value.substring(0, maxAmount); } else { showCountField.value = maxAmount - textField.value.length; } } </script> <form method="post" enctype="multipart/form-data" id="formAd"> Line 1: <input type="text" placeholder="Remaining Characters" autofocus style="width: 250px;" name="Line1" maxlength="28" onKeyDown="textCounter1(this.form.Line1,this.form.countDisplay1);" onKeyUp="textCounter1(this.form.Line1,this.form.countDisplay1);"/><input readonly type="text" style="width: 35px;" name="countDisplay1" size="2" maxlength="2" value="28"/><input type="checkbox" name="bold" value="1"/> <strong> Make the first line bold.</strong><br> <button>Submit</button> </form>Outputs:array(2) { ["Line1"]=> string(16) "http://test.test" ["countDisplay1"]=> string(2) "12" } Can you do something quick for me? Using Chrome, open the Developer Tools by pressing Ctrl+Shift+I, or by going to the menu > More Tools > Developer Tools. Once open, go to the Network tab at the top, and then submit your form. This will capture the request sent to your PHP script. You can click on the new entry and view details of the request to the right. I'd like you to post the "Request Headers" and "Request Payload" sections here. A screenshot would be perfect. I've added an example screenshot below. Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519842 Share on other sites More sharing options...
Sedona Posted August 28, 2015 Author Share Posted August 28, 2015 array(0) { } New record created successfully Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519845 Share on other sites More sharing options...
scootstah Posted August 28, 2015 Share Posted August 28, 2015 Okay, so the value is there properly in the request. What is that empty array you posted last, is that $_POST? It might also help to post the output from file_get_contents('php://input');, as well as phpinfo();. Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519846 Share on other sites More sharing options...
Sedona Posted August 28, 2015 Author Share Posted August 28, 2015 It was the result of the submit, the empty array. Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519847 Share on other sites More sharing options...
scootstah Posted August 28, 2015 Share Posted August 28, 2015 Okay, I was interested in this value: upload_max_filesize which is set to the default 2M. Since you're using enctype=multipart/form-data, it's going to take this value into consideration. According to your request the content-length is only 1.5MB, but I'm not sure what other overhead it may be counting. So I would go ahead and increase that value in the php.ini and see if that helps things. Something like 10M or 20M should be okay. Make sure to restart apache afterwards. Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519849 Share on other sites More sharing options...
Sedona Posted August 28, 2015 Author Share Posted August 28, 2015 OK, I will do that, but I am really only sending a payload of 20bytes or so, aren't I? Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519850 Share on other sites More sharing options...
Sedona Posted August 28, 2015 Author Share Posted August 28, 2015 It looks like it is already set to 32mb's , from the config: upload_max_filesize Maximum allowed size for uploaded files. 32M Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519851 Share on other sites More sharing options...
scootstah Posted August 28, 2015 Share Posted August 28, 2015 Are you sure you're in the right file? According to the phpinfo you posted, it is only set to 2M. Loaded Configuration File /opt/alt/php56/etc/php.ini Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519854 Share on other sites More sharing options...
Sedona Posted August 28, 2015 Author Share Posted August 28, 2015 Found it and bumped it up to 32mbs. No change. Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519856 Share on other sites More sharing options...
scootstah Posted August 28, 2015 Share Posted August 28, 2015 It looks like you may be using FastCGI instead of mod_php5. So, there should be a PHP service that you need to restart before the change to the php.ini would take affect. I'm not sure what your hosting environment is, or if you're on a VPS or what, but the service is usually like php-fpm or php5-fpm or something like that. Restarting the whole machine would work too, if that is an option. Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519857 Share on other sites More sharing options...
scootstah Posted August 28, 2015 Share Posted August 28, 2015 Actually, you know what - I'm totally on the wrong path here. I left out an order of magnitude on your request size - it's only 1.5KB, not 1.5MB. So the upload size is most certainly not the problem here. Did you try getting output from this: file_get_contents('php://input'); after your form submission? Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519861 Share on other sites More sharing options...
Sedona Posted August 29, 2015 Author Share Posted August 29, 2015 (edited) I am not quite sure how to implement that. Edited August 29, 2015 by Sedona Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519864 Share on other sites More sharing options...
scootstah Posted August 29, 2015 Share Posted August 29, 2015 The same way you got this result earlier by dumping the $_POST: array(0) { }So just do this in the same place:var_dump(file_get_contents('php://input')); Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519865 Share on other sites More sharing options...
Sedona Posted August 29, 2015 Author Share Posted August 29, 2015 Ok, thanks! I added these to the POST catch file: var_dump(file_get_contents('php://input')); var_dump($_POST); And it returned: string(0) "" array(0) { } Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519866 Share on other sites More sharing options...
scootstah Posted August 29, 2015 Share Posted August 29, 2015 Huh, that's pretty dang weird. I noticed that you have errors turned off in your php.ini. Can you add this to the top of your script that processes the form? ini_set('display_errors', 'On'); error_reporting(-1);Please post back any errors that you receive. Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519867 Share on other sites More sharing options...
Sedona Posted August 29, 2015 Author Share Posted August 29, 2015 This is the full error: string(0) "" array(0) { } Notice: Undefined index: Line1 in /home/sedoyrzi/public_html/Ads/placeAd.php on line 29 Notice: Undefined index: Line2 in /home/sedoyrzi/public_html/Ads/placeAd.php on line 31 Notice: Undefined index: Line3 in /home/sedoyrzi/public_html/Ads/placeAd.php on line 32 Notice: Undefined index: Line4 in /home/sedoyrzi/public_html/Ads/placeAd.php on line 33 Notice: Undefined index: Line5 in /home/sedoyrzi/public_html/Ads/placeAd.php on line 34 Notice: Undefined index: Line6 in /home/sedoyrzi/public_html/Ads/placeAd.php on line 35 Notice: Undefined index: weeks in /home/sedoyrzi/public_html/Ads/placeAd.php on line 36 Notice: Undefined index: email in /home/sedoyrzi/public_html/Ads/placeAd.php on line 37 Notice: Undefined index: comment in /home/sedoyrzi/public_html/Ads/placeAd.php on line 38 New record created successfully Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519868 Share on other sites More sharing options...
scootstah Posted August 29, 2015 Share Posted August 29, 2015 So you're saying that if you literally type "ttp://www.mariposa.com" it works, but "http://www.mariposa.com" doesn't? That's crazy... I'm out of ideas for the moment. Normally, from my experience, when the $_POST is empty it is usually because you exceeded the max POST size setting. But, you have not, in this case. I noticed that you are using enctype="multipart/form-data", but you aren't uploading any files. Why is that? Just for giggles, try removing that attribute from your form completely and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519869 Share on other sites More sharing options...
Sedona Posted August 29, 2015 Author Share Posted August 29, 2015 string(0) "" array(15) { ["Line1"]=> string(22) "ttp://www.mariposa.com" ["countDisplay1"]=> string(1) "6" ["Line2"]=> string(0) "" ["countDisplay2"]=> string(2) "28" ["Line3"]=> string(0) "" ["countDisplay3"]=> string(2) "28" ["Line4"]=> string(0) "" ["countDisplay4"]=> string(2) "28" ["Line5"]=> string(0) "" ["countDisplay5"]=> string(2) "28" ["Line6"]=> string(0) "" ["countDisplay6"]=> string(2) "28" ["weeks"]=> string(0) "" ["email"]=> string(0) "" ["comment"]=> string(0) "" } New record created successfully Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519871 Share on other sites More sharing options...
Sedona Posted August 29, 2015 Author Share Posted August 29, 2015 Pulling the enctype="multipart/form-data" didn't change the result. Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519872 Share on other sites More sharing options...
scootstah Posted August 29, 2015 Share Posted August 29, 2015 (edited) Ha, that's pretty whack indeed. I am pretty intrigued at this point. Is there any way that you can share enough of your application so that I can try to re-create the problem on my end? I would only need the page your form is on, with any relevant Javascript, and the script to process your form. You can private message it to me if you don't want to post it publicly on the forum. I'm sort of learning towards a problem with server configuration at the moment, although I'm not sure what. Also something I just thought of - you don't have any sort of code that filters/sanitizes superglobals before they get to where you're processing the form, right? Edited August 29, 2015 by scootstah Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519873 Share on other sites More sharing options...
scootstah Posted August 29, 2015 Share Posted August 29, 2015 I tried the code you sent me and it works with no issue. Therefore, the problem must be either server configuration, or something elsewhere in your script. Is /Ads/placeAd.php a standalone file, or does it get include'd into some other script? I think it must be standalone right, since you're calling it directly from the form? Some things to try: - Create a new, blank standalone PHP file and change your form action to point to it. The only thing you will have in this file is: <?php var_dump($_POST); ?> Verify that $_POST is still empty. - Download Advanced Rest Client extension for Chrome to be able to send a POST request to your server without all of the other HTML/JS stuff running. Alternatively, you can use a CURL request from a command line. This should work: curl -X "POST" -d "Line1=http://www.mariposa.com/" http://url-to-php-file-here- Simplify code wherever possible to try to make something work. For example, remove all other form fields and just have Line1. If you do the test above you can skip this step, however if the test above works then go ahead with this test and see at what point you can get something to work. - Try to log the raw POST request that your webserver sees. If you're using apache there are some modules you can download to do this. The goal here is to see if your webserver is seeing the POST request properly, or if something weird is happening there. - Try (temporarily) replacing your php.ini with a fresh, default one. You can obtain one here. You can either use master or select your version of PHP from the tags. Assuming all the above tests fail, and your webserver sees the request properly, then somewhere between the webserver getting the request and PHP getting the request something is going wrong. Quote Link to comment https://forums.phpfreaks.com/topic/297969-my-html-form-will-not-save-a-url-to-mysql/#findComment-1519874 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.