6

This should be a very basic question in PHP, but I couldn't get a nice solution in web. Please some experts show me with example.

I am trying to read value of 3 textboxes, those names are input_38.1, input_38.2, input_38.3

so my code is echo $_POST['input_38.1']. But it doesn't print the 1st textbox's value. What is the way to get all three textbox's values.

Thanks in advance.

John Supakin
  • 141
  • 5
  • 14
  • 2
    Can you show your whole code including the form and not just snippets? It's hard to identify the problem with the information you supplied. – Ali Dec 13 '13 at 20:30
  • 2
    Change the echo to: `echo $_POST['input_38_1'];` – JTFRage Dec 13 '13 at 20:32

2 Answers2

18

I am trying to read value of 3 textboxes, those names are input_38.1, input_38.2, input_38.3

From the PHP Manual:

Dots and spaces in variable names are converted to underscores. For example <input name="a.b" /> becomes $_REQUEST["a_b"].

So, you'd need to write:

echo $_POST['input_38_1'];

To avoid confusion, it's a good idea not to use dots in your form's name attributes.

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
  • 1
    Well, I didn't know that, you learn something every day. :) Skimming further down that page (which is badly in need of updating) reveals why: our old "friend" `register_globals` would have turned it into an invalid variable name ("For the reason, look at it" as the page rather chattily puts it). Similar restrictions (normally) apply to sessions, such as the one discussed here: http://stackoverflow.com/a/18797380/157957 – IMSoP Dec 13 '13 at 20:37
2

You need to change your echo statement:

$_POST['input_38_1'];

I usually stay away from using dots in my variable names.

JTFRage
  • 387
  • 7
  • 20
  • 1
    Great. Thanks JTFRage. I didn't use DOT. it is a form, so automatically the name comes with dot. when I use '_' for dot positions, it returns the value. thanks . – John Supakin Dec 13 '13 at 20:58