通过GET方法获取值后无法打印
问题描述:
我想通过GET方法获取两个文本框的值。但是当我尝试打印他们两个。我无法做到。当我用单个文本框完成代码时,代码完美地工作。通过GET方法获取值后无法打印
<?php
if(isset($_GET['name']) && isset($_GET['id']))
{
$username = $_GET['name'];
$userid = $_GET['id'];
echo 'Hi '.$username.'<br>';
echo "Emp Id is ".$userid;
}
?>
<form action="contact-DB.php" method="GET">
Enter Employee Name : <input type = "text" name = "name"><br>
Enter Employee ID : <input type = "text" name = "id">
<input type = "button" name="submit" value="Submit">
答
当您提交表单时,应该有一个提交按钮。在你的情况下,没有提交按钮。这就是表单从未提交的原因。
请尝试下面的例子:
<!DOCTYPE html>
<html>
<body>
<?php
if(isset($_GET['name']) && isset($_GET['id'])) {
$username = $_GET['name'];
$userid = $_GET['id'];
echo 'Hi '.$username.'<br>';
echo "Emp Id is ".$userid;
}
?>
<form action="contact-DB.php" method="GET">
Enter Employee Name :
<input type = "text" name = "name">
<br>
Enter Employee ID :
<input type = "text" name = "id">
<input type = "submit" name="submit" value="Submit">
</form>
</body>
</html>
在你的情况从来没有提交,因为你在if语句得到
<input type = "button" name="submit" value="Submit">
答
<input type="button" /> buttons will not submit a form - they don't do anything by default. They're generally used in conjunction with JavaScript as part of an AJAX application.
<input type="submit"> buttons will submit the form they are in when the user clicks on them, unless you specify otherwise with JavaScript.
所以用这个
<input type="submit" value="Submit" name="submit">
形式? – Unex
“无法做到”是什么意思?你的输出是什么? –
当我尝试从单个文本框中回显值时。它的作品,但是当我做同样的2个文本框。回声声明不起作用。 – user3196569