PHP: get the value of TEXTBOX then pass it to a VARIABLE

假装没事ソ 提交于 2019-12-23 02:56:53

问题


Good Day!.

I need a kinda little help for PHP. I’m really really newbie for PHP and I already search it to google and can’t find any solution.

My Problem is:

I want to get the value of textbox1 then transfer it to another page where the value of textbox1 will be appeared in the textbox2.

Below is my codes for PHP:

<html>
<body>

<form name='form' method='post' action="testing2.php">

Name: <input type="text" name="name" id="name" ><br/>

<input type="submit" name="submit" value="Submit">  

</form>
</body>
</html>

I also add the code below and the error is “Notice: Undefined index: name”

<?php 
$name = $_GET['name'];
echo $name;
?>

or

<?php 
$name = $_POST['name'];
echo $name;
?>

回答1:


Your method is post, so use $_POST

Also, try wrapping it around an isset function:

 if (isset($_POST['name'])){
    echo $_POST['name'];
 }   

This will also handle the undefined error




回答2:


This would be your textbox2:

<input type="text" name="textbox2" id="name" <?php echo (isset($_POST['name']) ? 'value=' .htmlspecialchars($_POST['name']). ' : ''); ?>/>

If you want to use the GET method, change post to get in your form and $_POST to $_GET in the php code of textbox2



来源:https://stackoverflow.com/questions/17014520/php-get-the-value-of-textbox-then-pass-it-to-a-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!