gpt4 book ai didi

php - HTML 和 PHP : how to manage a button in a form

转载 作者:行者123 更新时间:2023-11-28 05:17:50 25 4
gpt4 key购买 nike

我知道这可能是个愚蠢的问题,但我真的快要疯了。

我是 PHP 的新手,我想创建一个这样的表单

enter image description here

用户输入姓名和餐厅评论的位置,单击按钮时,必须将数据添加到页面中其他评论的下方。我在 HTML 中尝试了这段代码来创建表单

<form action="aggRecensione.php" method="post">
<p class="noIndent">Nome: <input type="text" name="nome"></p>
<p class="noIndent">Recensione</p>
<textarea name="recensione" rows="3" cols="40"></textarea>
<input type="submit" value="Aggiungi recensione" name="pulsanteRecensione" onclick="location.href='aggRecensione.php';">
</form>

以及这段 PHP 代码 (aggRecensione.php)

<?php
$nome = $_POST('nome');
$testo = $_POST('recensione');
echo "<p class=\"noIndent\">Recensione di $nome:</p>";
echo "<p>$testo</p>";
?>

但是 PHP 不工作。我以前从未管理过按钮,我找到的所有教程都没有帮助我。我做错了什么?

最佳答案

差不多好了,但也许你可以试试

<?php
$nome = $_POST['nome'];
$testo = $_POST['recensione'];
echo "<p class=\"noIndent\">Recensione di $nome:</p>";
echo "<p>$testo</p>";
?>

那是因为$_POST的内容是一个数组,数组键用括号[]表示

同时删除 onclick="location.href='aggRecensione.php';"

为了确保用户真的点击了按钮,你也可以添加这个

<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$nome = $_POST['nome'];
$testo = $_POST['recensione'];
echo "<p class=\"noIndent\">Recensione di $nome:</p>";
echo "<p>$testo</p>";
}
?>

http://php.net/manual/en/reserved.variables.post.php

关于php - HTML 和 PHP : how to manage a button in a form,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42887778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com