繁体   English   中英

提交php表单后如何显示结果

[英]how to display the result after the submit php form

提交表格后如何显示结果

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

示例1st im填写表单在提交之后提交结果我希望屏幕显示相同的结果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('','','','','','','','');
     }

    ?>

不太了解您的要求。

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

要显示它,您只需要制作一个显示它的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
}

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

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

    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 
         }
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM