猿问

if (isset($_POST[echo $_POST

我需要一些编码方面的帮助。


我从 W3Schools 和 youtube 上看了一些教程,但我就是不明白。


<!DOCTYPE html>

<?php

if (isset($_POST["Push me"]))


echo $_POST['name']

?>

<html>

<body>

Registration

<form action="/action_page.php" method="get" target="_blank">

  Insert name <input type="text" name="fname"><br>


  <input type="submit" value="Push me">



</form>


</body>

</html>

当您按下按钮时,应该在字段中输入一个名称。


示例:如果您在按下按钮后输入名称 Simon,则应在按钮下方写上 Hello Simon


撒科打诨
浏览 226回答 2
2回答

富国沪深

你的 PHP 代码在 HTML 标签之外,我已经将 php 代码放在按钮下的 DIV 中,即显示“Hello xxxTheNameYouEnterInTheInputxxx”如果条件在你的PHP代码应该是这样if(isset($_POST["fname"]))的,而不是if(isset($_POST["Push me"])) 如$ _ POST [“NameOfTheInputElementInTheForm”]<form action="/action_page.php" method="get" target="_blank">应该像<form action="/test.php" method="POST">ie Method 是 POST 并且 action 应该是文件名,删除target="_blank"这是完整的代码,另存为 test.php<!DOCTYPE html><html>&nbsp; &nbsp; <body>&nbsp; &nbsp; &nbsp; &nbsp; Registration&nbsp; &nbsp; &nbsp; &nbsp; <form action="/test.php" method="POST">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Insert Name: <input type="text" name="fname"><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="submit" value="Push me">&nbsp; &nbsp; &nbsp; &nbsp; </form>&nbsp; &nbsp; &nbsp; &nbsp; <hr>&nbsp; &nbsp; &nbsp; &nbsp; <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (isset($_POST["fname"])){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "Hello " . $_POST['fname'];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ?>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; </body></html>

墨色风雨

if (isset($_POST["fname"]))//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^^^^^echo $_POST['fname'];//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^^^^^&nbsp; ^<form action="/action_page.php" method="post" target="_blank">//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^^^^
随时随地看视频慕课网APP
我要回答