如何将html表单与php链接,以便在例如单击按钮时返回true

How do I link a html form with php, so that when clicking on a button for example, will return true?

本文关键字:单击 按钮 true 返回 html 表单 链接 php      更新时间:2024-03-29

我是php的新手,我想知道如何创建一个php在按钮后台运行的按钮?对不起,如果我说的不是很清楚。

此外,在社交网站中,如果该按钮会用新信息/文本刷新网页,我如何加载新信息以及删除旧信息?

1)只需使用POST方法创建一个HTML表单并对页面本身进行操作。当使用按钮发送数据时,PHP可以分析POST请求并执行任何您想要的操作。

2) 你可能指的是Web2.0。像Facebook这样的网站使用JavaScript对其后端进行异步Ajax调用,然后用新的信息替换屏幕上的信息,而无需重新加载页面。

我不确定这是否是php特有的。但是php函数中有一个按钮,它可以执行某些操作,从而获得其他信息。

<?php
function button(){
    if(isset($_GET['button'])) {
        // this information is shown when the get variable 'button' is set. The var $_GET['button'] is shown too in the case.
        echo "The button is clicked, it contains the following GET value: {$_GET['button']}";
    } else {
        // this information is only shown when there is no variable set in the URL, like 'button=clicked'
        echo "The button is not clicked yet.";
    }
    echo "<a href='?button=click'>Click on the button</a>";
}
// here the function is called.
button();
?>