Jump to content

Recommended Posts

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?

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;
	}
}

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;
}

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.

 

Uks9Cw9.png

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.

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.

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?

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.

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

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.

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

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 by scootstah

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.

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.