3 回答
TA贡献1876条经验 获得超7个赞
在 check.php 中,您应该将 $name_result 声明为空字符串。并且为了访问 post 变量或获取数据,它们应该有一个 name 属性。所以,给提交按钮一个特定的名称,如您正在使用的提交。
此外,您在
$name_result = 'welcome ' . $gender . $name];
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Contact form</h1>
<form method="POST" action="check.php">
<div>
<div>
<label for="" class="font">Title:</label>
<label for="" class="font">Name:</label>
</div>
<div>
<div>
<input type="radio" name="gender" value="Mr.">Mr.
<input type="radio" name="gender" value="Ms.">Ms.
<input type="text" name="name" value="" class="text"><br>
</div>
<br>
<div>
<input type="submit" value="submit" name="submit">
</div>
</form>
</body>
</html>
检查.php
<?php
$gender = $_POST['gender'];
$name = $_POST['name'];
$name_result='';
if(isset($_POST['submit'])){
if(isset($_POST['gender'])){
$name_result = 'welcome ' . $gender .' '. $name;
}else{
$name_result = 'Oops! No name typed';
}
}
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>confirm</h1>
<div>
<p><?php echo $name_result; ?></p>
</div>
</body>
</html>
TA贡献1807条经验 获得超9个赞
为您的提交按钮命名 name="submit"
<input type="submit" value="submit" name="submit">
将 $name_result 定义为全局变量
<?php
$gender = $_POST['gender'];
$name = $_POST['name'];
$name_result="";
if(isset($_POST['submit'])){
if(isset($_POST['gender'])){
$name_result = 'welcome ' . $gender . $name];
}else{
$name_result = 'Oops! No name typed';
}
}
?>
- 3 回答
- 0 关注
- 121 浏览
添加回答
举报