PHP 表单设置不起作用


PHP form isset not working

当用户在输入姓名和年龄后提交时,代码不起作用。页面应提交到同一页面,HTML 表单也应与下面的结果一起显示。请帮帮我!!

<html>
<head>
	<title>My first PHP page</title>
</head>
<body>
		<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <!-- $_SERVER['PHP_SELF'] array -->
			Name: <input type="text" name="name"/>
			Age: <input type="text" name="age"/>
			<input type="submit"/>
		</form>
</body>
</html>

<?php
/* because both the HTML form data and the PHP processing code are in the same script, you will need a conditional check to 
   see if the form has been submitted */
    if ( isset($_POST['submit']) ) { //was the form submitted?
        print "Raveen";
        //echo "Welcome ". $_POST["name"] . "<br>";
        //echo "You are $_POST["age"] years old<br>";
        //echo "The path to this file is: $_SERVER[PHP_SELF]";
    }
?>

你需要给名字才能得到帖子名称

<input name="yourformname" ...

之后,您可以检查帖子名称

like:  if ( isset($_POST['yourformname']) ) {

一定是这样的

 <input name="submit" type="submit" />

还有另一种方法可以了解如何获得帖子。 外汇 在您的表单中创建一个隐藏的输入,例如:

    <html>
    <head>
        <title>My first PHP page</title>
    </head>
    <body>
            <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <!-- $_SERVER['PHP_SELF'] array -->
                Name: <input type="text" name="name"/>
                Age: <input type="text" name="age"/>
<input type="hidden" name="gotit"/>
                <input type="submit"/>
            </form>

    </body>
    </html>

之后,您可以检查

<?php
/* because both the HTML form data and the PHP processing code are in the same script, you will need a conditional check to 
   see if the form has been submitted */
    if ( isset($_POST['gotit']) ) { //was the form submitted?
        print "Raveen";
        //echo "Welcome ". $_POST["name"] . "<br>";
        //echo "You are $_POST["age"] years old<br>";
        //echo "The path to this file is: $_SERVER[PHP_SELF]";
    }
?>