Reputation: 8538
got a small problem, this code
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<?php
...
echo '<input name="textfield" type="text" id="textfield" value="Roger" />';
echo 'Hello, '.$_POST['textfield'].'<br>';
...
?></p>
</form>
should echo out "Hello, Roger", as roger is the default value, yet it gives out only "Hello, " and nothing else. Any suggestions?
edit: yes, there's a form.
Thanks!
Upvotes: 0
Views: 1627
Reputation: 382616
You are echoing the text box and at the same time hoping to gets its value, which is not possible.
echo '<input name="textfield" type="text" id="textfield" value="Roger" />';
echo 'Hello, '.$_POST['textfield'].'<br>';
You need to first submit the form with method set to post
and only then you can get its value.
Example:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
...
<input name="textfield" type="text" id="textfield" value="Roger" />
...
<input name="submit" type="submit" id="submit" value="submit" />
</form>
PHP
if (isset($_POST['submit']))
{
echo 'Hello, '.$_POST['textfield'].'<br>';
}
Upvotes: 7
Reputation: 4569
My guess it, that the server doesn't allocate $_GET
and/or $_POST
. You could check that in the php configuration.
Have a look if you can access the data via $_REQUEST
, which should unify get and post data.
Upvotes: 0
Reputation: 17750
If this is, exactly, your code then the problem is that the $_POST is not set yet since no form is submitted.
Upvotes: 2
Reputation: 15241
Upvotes: 0
Reputation: 19432
Try print_r($_POST)
or var_dump($_POST)
to see if any POST data gets submitted.
Edit: Did you specify POST as the submit method in your form tag? Do you submit the form? Please show the entire <form>
-Tag.
Upvotes: 3