[英]In PHP how do I send form data to a page but direct the user to another when he clicks the submit button?
[英]I'm trying to link my form to my PHP page, and I want to print out the user's input onto that page when he clicks the submit button
我已经尝试过在表单中使用GET方法,在PHP页面中使用$ _GET方法,但是它没有将两者链接在一起。 我想在用户单击提交按钮时以用户输入的形式打印出元素。 这是我用于表单的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MY Form</title>
</head>
<body>
<form action="q4.php" method="get">
<label><b>First Name:</b></label><br />
<input type="text" name="first_name"><br />
<label><b>Last Name:</b></label><br />
<input type="text" name="second_name">
<br>
<label for="status">Status</label><br>
<select name="status" id="status">
<option value="undergraduate">UnderGraduate</option>
<option value="postgraduate">Postgraduate</option>
<option value="alumni">Alumni</option>
</select>
<br><br><br>
<input type="radio" name="continuing">Continuing<br>
<input type="radio" name="continuing">Not Continuing<br>
<br><br>
<label>Satisfaction Level <br></label>
<label>0</label><input type="range" name="satisfaction" min="0" max="100"/><label>100</label>
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
这是我用于PHP的代码:
<?php
$names = array(first_name => '', second_name => '');
reset($names);
while (list($key, $val) = each($names)) {
echo "$key => $_GET\n";
}
?>
如果要打印所有结果,可以执行以下操作
<?php
foreach($_GET as $key => $value){
echo $key.": ".$value;
}
?>
但是,如果您只希望显示特定数据,那么可能是这样的
<?php
$names = array(first_name => '$_GET['first_name']', second_name => 'second_name');
foreach($names as $name => $value){
echo $name.": ".$value;
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.