1

This is my page:

    <?php

require_once '\..\core\init.php';
error_reporting(E_ALL); 
ini_set('display_errors', TRUE);

session_start();
$data = array();
$mes_formulario = $_GET['mes'] ?? date('m-Y');
$dia = date_create_from_format('m-Y', $mes_formulario);
$mes = $dia->format('n');
$inicio = date_create_from_format('j-n', '15-'.$mes);
$fin = date_create_from_format('j-n', '15-'.$mes+1);

$aprobado = $consulta->consultauni("SELECT COUNT(*) as Q from base WHERE CERTI = 'SI' AND EMPRESA = 'SOMETHING' AND FECHA_ENVIO >= ". $inicio . "AND FECHA_ENVIO < " . $fin);


$data['aprobado'] = $aprobado;


$data['mes']  = date_create_from_format('j-n', '1-'.$mes);
$_SESSION['datos_cuadro'] = $data;
if(!headers_sent()) {
    header("Location: vista_bec.php");
}

I usually work with framework PHP so plain old PHP is new to me. I've read a few solutions to this but none of them applied to my case. PHP file for the redirection is within the same folder as this file. No errors get displayed.

EDIT:

Changed the code to this quickly but still get a blank page:

$data = array();
$mes_formulario = $_GET['mes'] ?? date('m-Y');
$dia = date_create_from_format('m-Y', $mes_formulario);
$mes = $dia->format('n');
$inicio = date_create_from_format('j-n', '15-'.($mes));
$inicio = $inicio->format('Y-m-d');
$fin = date_create_from_format('j-n', '15-'.($mes+1));
$fin = $fin->format('Y-m-d');
ffuentes
  • 770
  • 3
  • 10
  • 26
  • Try an `absoluteURI`? ..."The field value consists of a single absolute URI." – ficuscr Aug 06 '19 at 21:44
  • why? it's not like I'm getting a 404 error. It's just not redirecting anywhere. – ffuentes Aug 06 '19 at 21:45
  • Aren't those variables you're putting into the SQL DateTime objects? That won't work, will it? – Don't Panic Aug 06 '19 at 21:45
  • Then you are getting an error you are not telling us about? Or sending output prior to headers most likely. As to why? Because that is how the RFC is written - I too would think it should work as is. – ficuscr Aug 06 '19 at 21:46
  • 1
    This is a bug: `'15-'.$mes+1`. It should be: `'15-'.($mes+1)`. – KIKO Software Aug 06 '19 at 21:46
  • I'm not getting an error but what Don't Panic says makes sense. – ffuentes Aug 06 '19 at 21:47
  • That should result in "Catchable fatal error: Object of class DateTime could not be converted to string" – Don't Panic Aug 06 '19 at 21:47
  • 2
    If you don't have [error reporting](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) on you won't see the error. – Don't Panic Aug 06 '19 at 21:48
  • 1
    Regarding your edit - the dates will need to be quoted in your SQL. – Don't Panic Aug 06 '19 at 21:54
  • Check the edit please and error reporting is enabled or so I think in line 3 and 4. – ffuentes Aug 06 '19 at 21:54
  • Oh you're right about the error reporting, I'm sorry I didn't notice that. The code works okay for me. Though I'm not executing any SQL, it does redirect. Maybe the error is in the required file, in something that runs before you turn on error reporting. – Don't Panic Aug 06 '19 at 21:55
  • Well for sanity... `if(!headers_sent()) { header("Location: vista_bec.php"); exit; } else {die('well there is your problem');}` – ficuscr Aug 06 '19 at 21:59
  • I fixed it with your tip about dates without quotes and I double checked my routes. – ffuentes Aug 07 '19 at 15:41

0 Answers0