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



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

<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 已下载,但在报告中未获得 $_GET("数字".php . 如何知道参数是否传递。 我附上了我页面的完整编码。

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

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

请尝试下面的代码,它将帮助您获取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();

相关内容

  • 没有找到相关文章

最新更新