1

提交表单后如何显示结果

提交打印表单后我想要显示结果

示例第一个我填写表单提交提交后的结果我想要一个屏幕显示相同的结果 http://www.tizag.com/phpT/examples/formexample.php

我该怎么做,请帮我解决这个问题。

php表单代码

<?php
     function renderForm($grn, $name, $rollno, $class, $fees, $date, $reference, $error)
     {
     ?>
     <?php 
     if ($error != '')
     {
     echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
     }
     ?> 
     <form action="" method="post">
     <div>
       <p><span class="style9"><strong>G.R.N No:</strong></span><strong>  *</strong>
         <input name="grn" type="text" id="grn" value="<?php echo $grn; ?>" size="50" />
       </p>
       <p><span class="style9"><strong>Name:</strong></span><strong>  *</strong>
         <input name="name" type="text" id="name" value="<?php echo $name; ?>" size="50" />
       </p>

       <p><span class="style9"><strong>Roll No :</strong></span><strong>  *</strong>
         <input name="rollno" type="text" id="rollno" value="<?php echo $rollno; ?>" size="50" />
       </p>
       <p><span class="style9"><strong>Class:</strong></span><strong>  *</strong>
         <input name="class" type="text" id="class" value="<?php echo $class; ?>" size="50" />
       </p>
        <p><span class="style9"><strong>Fees Date  :</strong></span><strong>  *</strong>
          <input id="fullDate"  name="date" type="text" value="<?php echo $date; ?>" size="50" />
       </p>
        <p><span class="style9"><strong>Fees :</strong></span><strong>  *</strong>
          <input name="fees" type="text" value="<?php echo $fees; ?>" size="50" />
       </p>
        <span class="style9"><strong>Reference</strong></span><strong> *</strong>
        <input name="reference" type="text" value="<?php echo $reference; ?>" size="50">
        <br/>
       <p class="style1">* required</p>
     <input type="submit" name="submit" value="Submit">
     </div>
     </form> 
     <?php 
     }
     include('connect-db.php');

     if (isset($_POST['submit']))
     { 
     // get form data, making sure it is valid
     $grn = mysql_real_escape_string(htmlspecialchars($_POST['grn']));
     $name = mysql_real_escape_string(htmlspecialchars($_POST['name']));
     $rollno = mysql_real_escape_string(htmlspecialchars($_POST['rollno']));
     $class = mysql_real_escape_string(htmlspecialchars($_POST['class']));
     $fees = mysql_real_escape_string(htmlspecialchars($_POST['fees']));
     $date = mysql_real_escape_string(htmlspecialchars($_POST['date']));
     $reference = mysql_real_escape_string(htmlspecialchars($_POST['reference']));


     // check to make sure both fields are entered
     if ($grn == '' || $name == '' || $rollno == '')
     {
     // generate error message
     $error = 'ERROR: Please fill in all required fields!';

     // if either field is blank, display the form again
     renderForm($grn, $name, $rollno, $class, $fees, $date, $reference, $error);
     }
     else
     {
     // save the data to the database
      mysql_query("INSERT fees SET grn='$grn', name='$name', rollno='$rollno', class='$class', fees='$fees', date='$date', reference='$reference'")
     or die(mysql_error()); 
     echo "<center>KeyWord Submitted!</center>";
     // once saved, redirect back to the view page

     }
     }
     else
     // if the form hasn't been submitted, display the form
     {
     renderForm('','','','','','','','');
     }

    ?>
4

3 回答 3

0

不太清楚你在问什么。

您需要帮助显示提交的表单数据吗?或更具体的打印显示?

要显示它,您只需要制作一个html显示它的页面。像:

echo '<table><tr>';
  echo '<td>';
    echo '<Strong>Name:</strong><br/>';
    echo $name;
  echo '</td>';
echo '</tr></table>';

为了只显示结果而不是表单,当您发布到同一页面时,您需要使用 if 语句封装 for 代码。

if(isset($_POST['submit'])) {
  //code for the php form
}else {
  //code to display form
}
于 2013-04-09T07:20:26.010 回答
0

为表单中的“操作”部分使用新页面。在该新页面上,只需回显您要显示的值的 $_POST。如果您计划制作某种页面以便人们可以检查他们的条目,您可以将这些 $_POST 数据存储在会话中。

于 2013-04-09T07:21:58.433 回答
0

只需调用底部的函数即可显示发布的值:

    function showFormValues()
         {
         ?>


         <div>
           <p><span class="style9"><strong>G.R.N No:</strong></span><strong>  *</strong>
              <?php echo $_POST['grn']; ?>
           </p>
           <p><span class="style9"><strong>Name:</strong></span><strong>  *</strong>
              <?php echo $_POST['name'];
           </p>
and so on.
    .
    .
    .
    .
         </div>

         <?php 
         }
?>
于 2013-04-09T07:23:26.783 回答