1

I have 2 files. I'm trying to get the POST from one file to another, yet it's showing up as null for some reason. Please take a look:

testx1.php

<?php

echo "<form method = 'post' action = 'testx2.php'>";

echo "<input type = 'number' name = 'number'>";
echo "<input type = 'submit'>";

echo "</form>";

?>

testx2.php

<?php

$number = $_POST['number'];
echo $number;

?>

Expected output:

123

Actual output:

No output

Also, this shown up in the link for some reason:

/testx2.php?number=123
frosty
  • 2,559
  • 8
  • 37
  • 73
  • The reason that /testx2.php?number=123 is showing up as your address is because it thinks you are using the GET method instead of the POST method. – kojow7 Jun 12 '15 at 19:32
  • I'm using members.000webhost.com. It's a free web server. – frosty Jun 12 '15 at 19:33
  • `type="number"` has browser restrictions. I would suggest changing it to `type="text"` for the time being and testing that way. – the_pete Jun 12 '15 at 19:34
  • @kojow7 But I specifically mention that I wanted to use the POST method in my form. – frosty Jun 12 '15 at 19:34
  • @the_pete It works as a text. – frosty Jun 12 '15 at 19:35
  • @frosty if it works as text and not number then it looks like you're hitting a browser restriction. I copied your code line for line and it works for me with `type="number"` so try it in another browser or just keep it as text during your testing phase and switch it to number later. – the_pete Jun 12 '15 at 19:37
  • @frosty, yes, so there must be something else wrong with your code. Are you sure you copied and pasted all of your code exactly, because what you have here works fine. Maybe you forgot to close a quote or bracket, etc. in the original. – kojow7 Jun 12 '15 at 19:38
  • @the_pete type="number" will not change it from a POST to a GET request. There is something else going wrong here. In HTML standards if the type is not recognized it defaults to text anyhow. – kojow7 Jun 12 '15 at 19:40
  • 1
    @kojow I understand that, but aside from the misinterpretation of POST as GET, there could be another issue at hand and I'm addressing the problem from that side of things because the code works for me without issue. – the_pete Jun 12 '15 at 19:42
  • @frosty what browser and version are you using? – kojow7 Jun 12 '15 at 19:43
  • According to this link: http://stackoverflow.com/questions/2268868/webhoster-inserts-a-javascript-which-brokes-my-code-how-to-remove-it your webhost adds extra stuff to your page. Maybe try typing an exit command at the bottom of both of your scripts to see if this solves the issue. – kojow7 Jun 12 '15 at 19:52
  • Why are you using two different SO accounts? – kojow7 Jun 13 '15 at 05:25
  • @kojow7 because I can't ask questions on this one even though I have just as many upvotes as downvotes. – iscattered Jun 13 '15 at 16:47
  • It is because you were getting a lot of downvotes on this account. To be able to ask questions again fix your previous questions and/or start to get more upvotes by contributing good answers to other people's questions. Don't create a new account. – kojow7 Jun 13 '15 at 17:43
  • @kojow7 It's working again, for some reason. The number input. I didn't change anything. – frosty Jun 13 '15 at 18:32
  • @kojow7 This is insanity. It only works when I refreshed testx1.php to test it. If I don't refresh the page, nothing changes. That's why I wasn't getting the right outputs... – frosty Jun 13 '15 at 18:47
  • @frosty, yeah it helps to look at the page source code in the browser just to make sure it has the actual code you are expecting it to have. – kojow7 Jun 13 '15 at 19:56
  • @kojow7 Source code doesn't actually show the php code...does it? – frosty Jun 13 '15 at 20:02

2 Answers2

0

Works just fine for me. Tested on Apache server.

Have you tried it with a different browser? It looks look your browser is interpreting the HTML markup incorrectly.

You mentioned you're using a free web host which I would avoid, especially for development. A decent hosting package is available for just a few dollars a month like Hostgator for example. Some web hosts, especially free ones, add so many weird configurations to their servers to limit users and "secure" their server that it renders some code useless.

When developing try installing Mamp or Xampp and use that to test your code locally.

Syn
  • 331
  • 1
  • 13
-1

Maybe too late but you need to write "post" in Caps.

<?php

echo "<form method ="POST" action = 'testx2.php'>";

echo "<input type = 'number' name = 'number'>";
echo "<input type = 'submit'>";

echo "</form>";

?>
RBT
  • 24,161
  • 21
  • 159
  • 240
max
  • 1