1

我想制作一个文本字段和按钮,允许用户在文本字段中获取他的详细信息,而不是每次他想进行新的预订时都写他的详细信息。

就像这张照片: 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>   
4

2 回答 2

0

您将获得 2 个表单,因为如果$_POST['submit']已设置,您将回显一个表单,然后再回显另一个表单,不管任何情况。$_POST['submit']仅当未设置时才打印第二个表单。由于您的代码写得不好,我将给您举个例子:

if(isset($_POST['submit'])){
    PRINT FETCHED FORM
}else{
    PRINT EMPTY FORM
}

然而,这不是“正确”的方式。人们实际上所做的是在开始时将变量设置为空,然后在有请求时用数据填充它们,并在文件中写入一个表单,其中输入值作为这些变量。

于 2013-06-26T01:28:31.300 回答
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
    }
}
?>
于 2013-06-26T01:28:58.427 回答