Brigo
Brigo

Reputation: 1112

php.ini $_POST empty for unknown reason (localhost)

I usually automatically uploaded the scripts and test them on the remote hosting, but few days ago I installed the magic trio Apache, PHP and MySQL each one independently to test small problems faster. Today it came out that the $_POST array is totally empty. It's a basic form the one I'm testing and it perfectly works on the remote hosting, so I checked the php.ini file. I found that the enable_post_data_reading was set on Off and commented (although the documentation says it's enabled by default). I thought that was the problem but no. I restarted Apache and even the notebook but the $_POST array is still empty, outputing Notice: Undefined index: name in C:\Users\Marco\Proj\untitled\insert.php on line 3. Do anyone has any suggestion? (I'm passing just strings, so the problem is not even the post_max_size option) Thanks!

Although it's useless I anyway post the code

form.html

<form action="insert.php" method="post">
  <input type="text" name="name" placeholder="name" style="display:block" />
  <input type="text" name="code" value="" placeholder="code" style="display:block" />
  <input type="text" name="price" placeholder="price" style="display:block" />
  <label>Show</label><input type="checkbox" name="show" value="checked" />
  <input type="submit" value="inserisci" style="display: block" />
</form>

insert.php

<?php
include "filterFunctions.php";
$data = array("name" => $_POST["name"],
              "code" => $_POST["code"],
              "price" => $_POST["price"],
              "checkbox" => $_POST["show"]);
print_r($_POST);

[EDIT] Following Swatantra K's advice I checked if POST works using echo file_get_contents('php://input'); and this is what it displays:

------WebKitFormBoundarysqxwAAdf3E55NZUK Content-Disposition: form-data; name="name" Marco 
------WebKitFormBoundarysqxwAAdf3E55NZUK Content-Disposition: form-data; name="code" 35DW 
------WebKitFormBoundarysqxwAAdf3E55NZUK Content-Disposition: form-data; name="price" 99,9 
------WebKitFormBoundarysqxwAAdf3E55NZUK Content-Disposition: form-data; name="show" checked 
------WebKitFormBoundarysqxwAAdf3E55NZUK-- 

Notice: Undefined index: name in C:\Users\Marco\Proj\untitled\insert.php on line 4
Notice: Undefined index: code in C:\Users\Marco\Proj\untitled\insert.php on line 5
Notice: Undefined index: price in C:\Users\Marco\Proj\untitled\insert.php on line 6
Notice: Undefined index: show in C:\Users\Marco\Proj\untitled\insert.php on line 7
Array ( )

It means, I guess, that it works and that the inserted values exist, but I still can't figure out what's the problem and its solution. Also because var_dump($_POST); still displays array(0) { }. Any clue?

Upvotes: 1

Views: 911

Answers (2)

Swatantra Kumar
Swatantra Kumar

Reputation: 1330

Try setting

php_value post_max_size = 256M

or check if POST works

echo file_get_contents('php://input');

Upvotes: 1

Afzaal
Afzaal

Reputation: 42

you have two input field with name="name" so you are refering to both of these fields in php script, so remove one from it , and also define type attribute for form and assign value multipart. Hope this may work.

Upvotes: 0

Related Questions