dongshuan8722 2012-07-10 13:48
浏览 55
已采纳

你如何让PHP从HTML文本框中接收信息?

I'm trying to have an array display information inputted from a PHP-created HTML form. I'm trying to get the entire code on to one PHP file. So far, I have:

<body>
            <form action="hello.php" method="post">
                <input type="text" name="input" placeholder="Number" />
                <input type="submit" value="submit" onclick="go()" />
            </form>
        </body>

The above code is generated using "echo" in PHP (not shown).

Then for the rest of the PHP, I have:

function go() {

            $variable = "input";

That is just the beginning of my code. The rest is unimportant. I know the $variable = "input"; part is wrong, but how do I get numbers to transfer over from inputted HTML to PHP? Thanks a lot!

  • 写回答

1条回答 默认 最新

  • dongwo8827523 2012-07-10 13:50
    关注

    Since you're using a POST request you're going to want to refer to the $_POST superglobal. This variable is an array filled with any information sent by a POST request.

    Since you want to get the value from "input" you would call the the $_POST variable using the key of "input"

    function go() {
        $variable = $_POST['input'];
        // whatever else you want to do in your function
    }
    

    Since $_POST is a superglobal it is global in every scope.

    You don't need to include the onclick event for your submit button, unless you wanted to call a JavaScript event with it. But the mapping of the JavaScript function go() and the PHP function go() have ZERO correlation between the two.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名