开发者

Basic problem of getting values of my textbox

I am just trying to learn PHP and want to get the value of the textbox using $_post function, but its not working. I am using wamp 2.1 and the code is simple as below

<form method="POST" action="c:/wamp/www/test/try.php">
<input type="text" name="nco" size="1" maxlen开发者_如何学Pythongth="1" tabindex="1"  value="2">&nbsp;&nbsp;
<input
 tabindex="2" name="submitnoofcompanies" value="GO"
 type="submit">&nbsp;
</form>
<?php
 if (!isset($_POST['nco'])) 
{

$_POST['nco'] = "undefine"; 
}

$no=$_POST['nco'];
print($no);

However in no way I get the value of the textbox printed, it just prints undefined, please help me out.


You first assigned the word "undefine" to the variable $_POST['nco'].

You then assigned the value of the variable $_POST['nco'] (still "undefine" as you stored there) to the variable $no.

You then printed the value stored in the variable $no.

It should be clear that this will always print the word "undefine".

If you want to print the value of the textbox with the name nco, fill out the form with that textbox, and in the page that process the form,

echo $_POST['nco'];

...is all you do.


You need to setup a form or something similar in order to set the $_POST variables. See this short tutorial to see how it works. If you click the submit button, your $_POST variables will be set.


what for you are using this line $_POST['nco'] = "undefine"; } ..?

and please cross check whether you are using form method as post and make sure that your text name is nco ... or else use the below code it will work.

<?php
$no = $_POST['nco'];
echo $no;
?>
<form name='na' method='post' action="<?php echo $_SERVER['PHP_SELF'];?>">
  <input type='text' name='nco'>
 </form>

thanks


Your action is wrong.

Change it to

action="try.php"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜