我想创建一个文本字段和按钮,允许用户在文本字段中获取他的详细信息,而不是每次想要进行新预订时都写入他的详细信息。
像这张图片一样: http://oi41.tinypic.com/23ie70j.jpg我尝试使用我的代码进行此操作但是给了我双重表单,其中包含详细信息和一个没有。
<form method="post" action="reserv page.php">
enter the email: <input type = "text" name = "email"/>
<input type = "submit" name = "submit" value="submit" />
</form>
<?php
mysql_connect("localhost","userName","password");
mysql_select_db("database_Name");
if(isset($_POST['submit']))
{
$email = $_POST['email'];
$q = "SELECT * FROM tabe WHERE the_email = '$email'";
$run = mysql_query($q );
while($row = mysql_fetch_array($run))
{
?>
</br></br>
<form action="payment.php" method="post" >
First Name:<input name="fName" type="text" value="<?php echo $row[1]; ?>" />
Last Name: <input name="lNamet" type="text" value="<?php echo $row[2]; ?>" />
User Name: <input name="uName" type="text" value="<?php echo $row[3]; ?>"/>
Email: <input name="email" type="text" value="<?php echo $row[4]; ?>" />
password: <input name="pass" type="password" value="<?php echo $row[5]; ?>"/>
contact: <input name="number" type="text" value="<?php echo $row[6]; ?>" />
<input name="confirm" type="submit" value="Confirm" />
</form>
</br></br>
<?php
}}
?>
<form action="payment.php" method="post" >
First Name:<input name="fName" type="text" />
Last Name: <input name="lNamet" type="text" />
User Name: <input name="uName" type="text" />
Email: <input name="email" type="text" />
password: <input name="pass" type="password" />
contact: <input name="number" type="text" />
<input name="confirm" type="submit" value="Confirm" />
</form>
答案 0 :(得分:0)
你得到2个表单,因为如果设置了$_POST['submit']
,你就会回显一个表单,而不管是什么,都会回显另一个表单。仅在未设置$_POST['submit']
时才打印第二个表单。由于您的代码编写得很糟糕,我只想举个例子:
if(isset($_POST['submit'])){
PRINT FETCHED FORM
}else{
PRINT EMPTY FORM
}
然而,这不是“正确”的方式。人们实际上做的是在开始时将变量置为null,然后在有请求的情况下用数据填充它们,并在文件中写入一个表单并将输入值作为那些变量。
答案 1 :(得分:0)
<form method="post" action="reserv page.php">
enter the email: <input type = "text" name = "email"/>
<input type = "submit" name = "submit" value="submit" />
</form>
<?php
mysql_connect("localhost","userName","password");
mysql_select_db("database_Name");
if(isset($_POST['submit']))
{
$email = $_POST['email'];
//limit the query to one entry :)
$q = "SELECT * FROM tabe WHERE the_email = '$email' LIMIT 1";
$run = mysql_query($q );
//check if email is registered
if(mysql_num_rows($run)>0)
{
//display filled up form
while($row = mysql_fetch_array($run))
{
?>
</br></br>
<form action="payment.php" method="post" >
First Name:<input name="fName" type="text" value="<?php echo $row[1]; ?>" />
Last Name: <input name="lNamet" type="text" value="<?php echo $row[2]; ?>" />
User Name: <input name="uName" type="text" value="<?php echo $row[3]; ?>"/>
Email: <input name="email" type="text" value="<?php echo $row[4]; ?>" />
password: <input name="pass" type="password" value="<?php echo $row[5]; ?>"/>
contact: <input name="number" type="text" value="<?php echo $row[6]; ?>" />
<input name="confirm" type="submit" value="Confirm" />
</form>
</br></br>
<?php
}
}
//display blank form
else{
?>
<form action="payment.php" method="post" >
First Name:<input name="fName" type="text" />
Last Name: <input name="lNamet" type="text" />
User Name: <input name="uName" type="text" />
Email: <input name="email" type="text" />
password: <input name="pass" type="password" />
contact: <input name="number" type="text" />
<input name="confirm" type="submit" value="Confirm" />
</form>
<?php
}
}
?>