我有这个功能Utils.php
function GenerateMonthlyReport($connection, $month, $year, $objSheet)
{
$months = array("Enero", "Febero", "Marzo", "Abril", "Mayo", "Junio" ,"Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
$fromDate = $year . "-" . $month . "-01";
$toDate = "";
if ($month != 12)
$toDate = $year . "-" . ($month+1) . "-01";
else
$toDate = ($year+1) . "-01-01";
etc..
}
然后在另一个文件中我使用这样的参数createReport.php
调用这个函数$_POST
include "Utils.php";
include "Connect.php";
require_once('PHPExcel/Classes/PHPExcel.php');
checkLogin();
// Connect to Db
$connection = openDb();
// Input Data
$month = mysqli_real_escape_string($connection, $_POST["month"]);
$year = mysqli_real_escape_string($connection, $_POST["year"]);
$objPHPExcel = CreateEmptyWorkbook();
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007"); // create the writer
$objSheet = $objPHPExcel->getActiveSheet();
GenerateMonthlyReport($connection, $month, $year, $objSheet);
问题:我传递给函数 GenerateMonthlyReport$year
的参数在函数内部。$month
null
但如果我做这样的事情:
GenerateMonthlyReport($connection, "3", "2013", $objSheet);
它们被正确传递。
如果我回显$year
和$month
变量,它们会显示值!
另外:这种奇怪的行为只发生在我从移动设备提交表单时。PC 浏览器不会发生这种情况。
编辑:这是表单 HTML 代码:
<form id="reportForm" action="/service/createMonthlyReport.php" method="post">
<table border="1">
<tr>
<td>
Seleccione Período
</td>
<td>
<label>Mes</label><br/>
<select id="monthM" name="month" >
<?php for ($i=1; $i<=12; $i++) :?>
<option value="<?php echo $i; ?>" <?php echo date("n") != $i ? "" : "selected" ?>>
<?php echo $monthName = date("M", mktime(0, 0, 0, $i, 10)); ?>
</option>
<?php endfor; ?>
</select>
</td>
<td>
<label>Anio</label><br/>
<select id="yearM" name="year" >
<?php for ($i=-5; $i<=5; $i++) :?>
<?php $yearData = (date("Y") + $i); ?>
<option value="<?php echo $yearData; ?>" <?php echo date("Y") != $yearData ? "" : "selected" ?>>
<?php echo $yearData; ?>
</option>
<?php endfor; ?>
</select>
</td>
<td>
<input type="submit" value="Descargar Reporte Mensual" id="submitBtn" class="crearBtn" />
</td>
</tr>
</table>
</form>
开放数据库代码:
function openDb() {
$sever = "myserver";
$database_name = "dbname";
$user = "user";
$pass = "mypass";
$connection = new mysqli($server, $user, $pass, $database_name) or die("DB connection failed!");;
$connection->set_charset("utf8");
mysqli_query($connection, 'SET NAMES utf8');
mysqli_query($connection, 'SET CHARACTER SET utf8');
return $connection;
}