I have this function in 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..
}
Then in another file createReport.php
i call this function using $_POST
parameters
like this
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);
Problem: the parameters $year
and $month
that i am passing to the function GenerateMonthlyReport are null
inside the function.
But if i do something like this:
GenerateMonthlyReport($connection, "3", "2013", $objSheet);
they are passed correctly.
If i do a echo of $year
and $month
variables, they display values!!
Also: This strange behaviour only happens when i submit the Form from a Mobile Device. It does not happen from a PC browser.
EDIT: here is the Form HTML code:
<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>
openDB code:
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;
}