如何在php中传递参数?返回空值?

时间:2018-10-15 07:44:32

标签: php html codeigniter

我想在操作方法中传递参数,因为我无法在标头中传递参数。

<form name="mailinglist1" method="post" action="report1.php"  >

以这种形式,我正在使用下载按钮来连接我的报告(html)

$st1= 3106530;
header('Location: report1.php?num='.$st1 );

完整编码

                    <?php

                include("config/config.php");
                include("header.php");



                if(isset($_POST['search'])){
                $query1 = mysql_query("SELECT * from staff where staff_code=".$_POST['staff']);
                $row = mysql_fetch_array($query1);

                $query2=mysql_query("SELECT * from master_tab where  
                 deo_code =".$_POST['staff']
                );

                $query3 =mysql_query("select * from staff_bankinfo where staff_code=".$_POST['staff']);
                $row1 = mysql_fetch_array($query3);
                }
                else if(isset($_POST['contact']))
                {   


                    mysql_query("INSERT into staff_bankinfo (staff_code, bank_name,branch,ifsc,acno) values('$_POST[staf]', '$_POST[bank_name]','$_POST[branch]','$_POST[ifsc]','$_POST[acno]')") or die(mysql_error());
                       $msg= "Added";   

                }
                else
                {
                    //$sheet_no = 202565;
                    //header('Location: print_edit_mark_details.php?num='.$sheet_no);


                    header('Location: report1.php?num='.$_POST['staff']);

                    // echo "hai";


                }

                ?>



                        <?php include("theme.php"); ?>
                    </div><!-- /.ace-settings-container -->



             <form method="post" id="form_id" class="form-horizontal" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">                   

            <td align="center" colspan="6">
            <select name="staff" required>
            <option value="">Select Staff</option>
            <?php
               //dropdwon list based on query1
            <?php } ?>
            </select>
            </td>



         <!--2 input item from_date and to_date -->

             <label  for="mindate">From<span class="important"></span></label>
                          <td align="center">
                            <input type="date" name="mindate" id="login_id" placeholder="st date" value="<?php echo isset($_POST['mindate']) ? $_POST['mindate'] : '' ?>"   required> </td>
                          <label  for="maxdate">To<span class="important"></span></label>
                            <td align="center"><input type="date" name="maxdate" id="login_id" placeholder="end date" value="<?php echo isset($_POST['maxdate']) ? $_POST['maxdate'] : '' ?>"   required> </td>

                    <td align="center"><input name="search" type="submit" id="search" value="Submit" class="last btn btn-info"/></td>


            <br />
            <br />
            </form>
            <form name="mailinglist1" method="post" action="report1.php" >


                            <div class="row">
                                <div class="col-xs-12">
                                    <div class="table-header">
                                        Staff Details 
                                    </div>

                                <br />  
                                <div class="form-group">
                                    <!-- input item 1 fetched result from query1 -->
                                </div>
                                &nbsp;
                                <div class="form-group">
                                    <!-- input item 2  fetched result from query1 -->
                                    </div>
                                </div> &nbsp;   
                                <div class="form-group">
                                    <!-- input item 3  fetched result from query1 -->
                                </div>&nbsp;
                                <div class="form-group">
                                    <!-- input item 4  fetched result from query1 -->
                                </div> &nbsp;


                                <div class="form-group">
                                    <!-- input item 5  fetched result from query1 -->
                                </div>                                  
                                </div>                                  

                    </div>


           <br />


                    <div class="row">
                                <div class="col-xs-12">
                                    <div class="table-header">
                                        Bank Details 
                                    </div>
                                    <br />

                                <div class="form-group">
                                    <label class="col-sm-3 control-label no-padding-right" for="form-field-1">Bank Name
                                        <span class="important"></span></label>
                                    <div class="col-sm-9">


                                    <!-- input item 1  fetched result from query3 -->


                                </div>
                                &nbsp;
                                <div class="form-group">
                                    <!-- input item 2  fetched result from query3 -->
                                    </div>
                                </div> &nbsp;
                                <div class="form-group">
                                    <!-- input item 3  fetched result from query3 -->
                                    </div>
                                </div> &nbsp;
                                <div class="form-group">
                                    <!-- input item 4  fetched result from query3 -->
                                </div>



                                </div>                                  

                        </div>



       <br />



                            <div class="row">
                                <div class="col-xs-12">
                                    <div class="table-header">
                                        listing
                                    </div>



                                    <!-- div.table-responsive -->

                                    <!-- div.dataTables_borderWrap -->
                                    <div>


                                    <table id="dynamic-table" name="dynamic-table" class="table table-striped table-bordered table-hover">
                                    <thead>
                                            <!--table fetched values from query2 -->
                                            </table>        


                                    </div>
                                </div>
                            </div>


                        </div><!-- /.page-content -->

                    </div>
                    </div>  



            <br/>
            <div align="center">
            <input name="contact" type="submit" id="contact" value="Update" style="padding:5px" class="sendButton" disabled />&nbsp;&nbsp;&nbsp;



            <input name="download" type="submit" id="download" value="Download PDF" style="padding:5px" class="btn btn-danger" />&nbsp;&nbsp;&nbsp;


            </div>
            </label>
            </div>
            </form>


        </div><!-- /.main-content -->

        <div class="footer">
            <!-- footer -->
        </div>


       </div><!-- /.main-container -->      

pdf已下载,但未在report1.php中获得$ _GET('num')。如何知道是否传递参数。我附加了我页面的完整编码。

2 个答案:

答案 0 :(得分:2)

您通过POST方法发送表单,您的数据将通过邮寄发送。

通过$ _POST更改$ _GET或将表单方法更改为GET。

答案 1 :(得分:-1)

请尝试下面的代码,这将帮助您获取PHP文件中的值。

<?php
          include("config/config.php");
          include("header.php");

          if(isset($_POST['search'])){
          $query1 = mysql_query("SELECT * from staff where staff_code=".$_POST['staff']);
          $row = mysql_fetch_array($query1);

          $query2=mysql_query("SELECT * from master_tab where  
           deo_code =".$_POST['staff']
          );

          $query3 =mysql_query("select * from staff_bankinfo where staff_code=".$_POST['staff']);
          $row1 = mysql_fetch_array($query3);
          }
          else if(isset($_POST['contact']))
          {

              mysql_query("INSERT into staff_bankinfo (staff_code, bank_name,branch,ifsc,acno) values('$_POST[staf]', '$_POST[bank_name]','$_POST[branch]','$_POST[ifsc]','$_POST[acno]')") or die(mysql_error());
                 $msg= "Added";   

          }
          else
          {
              if ( isset($_POST['download']) && !empty($_POST['download']) ) {
                $staff_id = $_POST['staff_id'];
                if ($staff_id) {
                    header('Location: report1.php?num='.$staff_id);
                }
              }

          }

          ?>

                  <?php include("theme.php"); ?>
              </div><!-- /.ace-settings-container -->

       <form method="post" id="form_id" class="form-horizontal" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">                   

      <td align="center" colspan="6">
      <select name="staff" required>
      <option value="">Select Staff</option>
      <?php
         //dropdwon list based on query1
      <?php } ?>
      </select>
      </td>

   <!--2 input item from_date and to_date -->

       <label  for="mindate">From<span class="important"></span></label>
                    <td align="center">
                      <input type="date" name="mindate" id="login_id" placeholder="st date" value="<?php echo isset($_POST['mindate']) ? $_POST['mindate'] : '' ?>"   required> </td>
                    <label  for="maxdate">To<span class="important"></span></label>
                      <td align="center"><input type="date" name="maxdate" id="login_id" placeholder="end date" value="<?php echo isset($_POST['maxdate']) ? $_POST['maxdate'] : '' ?>"   required> </td>

              <td align="center"><input name="search" type="submit" id="search" value="Submit" class="last btn btn-info"/></td>

      <br />
      <br />
      </form>
      <form name="mailinglist1" method="post" action="report1.php" >

                      <div class="row">
                          <div class="col-xs-12">
                              <div class="table-header">
                                  Staff Details 
                              </div>

                          <br />  
                          <div class="form-group">
                              <!-- input item 1 fetched result from query1 -->
                          </div>
                          &nbsp;
                          <div class="form-group">
                              <!-- input item 2  fetched result from query1 -->
                              </div>
                          </div> &nbsp;   
                          <div class="form-group">
                              <!-- input item 3  fetched result from query1 -->
                          </div>&nbsp;
                          <div class="form-group">
                              <!-- input item 4  fetched result from query1 -->
                          </div> &nbsp;


                          <div class="form-group">
                              <!-- input item 5  fetched result from query1 -->
                          </div>
                          </div>
              </div>
     <br />
              <div class="row">
                          <div class="col-xs-12">
                              <div class="table-header">
                                  Bank Details 
                              </div>
                              <br />

                          <div class="form-group">
                              <label class="col-sm-3 control-label no-padding-right" for="form-field-1">Bank Name
                                  <span class="important"></span></label>
                              <div class="col-sm-9">

                              <!-- input item 1  fetched result from query3 -->

                          </div>
                          &nbsp;
                          <div class="form-group">
                              <!-- input item 2  fetched result from query3 -->
                              </div>
                          </div> &nbsp;
                          <div class="form-group">
                              <!-- input item 3  fetched result from query3 -->
                              </div>
                          </div> &nbsp;
                          <div class="form-group">
                              <!-- input item 4  fetched result from query3 -->
                          </div>

                          </div>

                  </div>

 <br />

                      <div class="row">
                          <div class="col-xs-12">
                              <div class="table-header">
                                  listing
                              </div>

                              <!-- div.table-responsive -->

                              <!-- div.dataTables_borderWrap -->
                              <div>

                              <table id="dynamic-table" name="dynamic-table" class="table table-striped table-bordered table-hover">
                              <thead>
                                      <!--table fetched values from query2 -->
                                      </table>        

                              </div>
                          </div>
                      </div>

                  </div><!-- /.page-content -->

              </div>
              </div>

      <br/>
      <div align="center">
      <input name="contact" type="submit" id="contact" value="Update" style="padding:5px" class="sendButton" disabled />&nbsp;&nbsp;&nbsp;

      <input name="download" type="submit" id="download" value="Download PDF" style="padding:5px" class="btn btn-danger" />&nbsp;&nbsp;&nbsp;
    <input type="hidden" name="staff_id" value="<?php // staff id which you will get from search form ?>">

      </div>
      </label>
      </div>
      </form>

  </div><!-- /.main-content -->

  <div class="footer">
      <!-- footer -->
  </div>

 </div><!-- /.main-container --> 

评论:

  

单击下载按钮时,人员ID应隐藏   领域。然后,只有您将获得工作人员ID。所以请检查值   使用print_r();

单击下载按钮