Jump to content

undefined function trigger_error()


gmc1103

Recommended Posts

Hi

 

I'm having problems with the following code and i can't find why

<?php
header('Content-Type: application/json');
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
$mysqli = new mysqli('localhost', 'xxxx', 'xxxxx');
if (mysqli_connect_errno()) {
    trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR);
}
$iduser = $_POST['iduser'];
$inicio = $_POST['inicio'];
$fim = $_POST['fim'];
$data = $_POST['data'];
$dia = $_POST['dia'];
$sala = $_POST['sala'];

$sql = "SELECT COUNT(id_dia) FROM `ebspma_paad_ebspma`. `sala_ocupacao` WHERE id_dia = ? AND id_sala= ? AND id_tempo = ? ";
$stmt = $mysqli->prepare($sql);
if ($stmt === false) {
      trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $mysqli->error, E_USER_ERROR);
}
$stmt->bind_param('iii', $dia, $sala, $inicio);
$stmt->execute();
$stmt->bind_result($existe);
$stmt->fetch();
$stmt->close();

if ($existe != 0) {
    $response = "Este dia já está registado na base de dados";
    echo json_encode(array('status' => 'error', 'message' => 'Este dia já está registado na base de dados'));
} else {
    $sql = "SELECT COUNT(*) AS total 
            FROM `req_material_reserva` 
            WHERE `req_material_reserva`.`idsala` = ?
            AND (((`req_material_reserva`.`idtempoInicio` BETWEEN ? AND ?) AND (`req_material_reserva`.`idTempoFim` BETWEEN ? AND ?))
            OR (`req_material_reserva`.`idtempoInicio` <= ? AND `req_material_reserva`.`idTempoFim` >= ?))
            AND `req_material_reserva`.`data` = ?";
    $stmt = $mysqli->prepare($sql);
    if ($stmt === false) {
          trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $mysqli->error, E_USER_ERROR);
    }
    $stmt->bind_param('iiiiiiis', $sala, $inicio, $fim, $inicio, $fim, $inicio, $fim, $data);
    $stmt->execute();
    $stmt->bind_result($total);
    $stmt->fetch();
    $stmt->close();

    if ($total != 0) {
        echo json_encode(array('status' => 'error', 'message' => 'Já existe uma reserva para dia/sala/hora'));
    } else {
        $sql = "INSERT INTO req_material_reserva(idutilizador, idsala, idtempoInicio, idTempoFim, data) VALUES(?, ?, ?)";
        $stmt = $mysqli->prepare($sql);
        if ($stmt === false) {
              trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $mysqli->error, E_USER_ERROR);
        }
        $stmt->bind_param('iiiis', $iduser, $sala, $inicio, $fim, $data);
        if (!$stmt->execute()) {
            echo json_encode(array('status' => 'error', 'message' => 'Opppss...O Registo não foi atualizado'));
        }
        $stmt->close();
        echo json_encode(array('status' => 'success', 'message' => 'O Registo foi atualizado corretamente'));
    }
}

Fatal error: Call to undefined function   trigger_error() in /home/ebspma/public_html/gestaosalas/reqSalasBd.php on line 39

 

This line

 trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $mysqli->error, E_USER_ERROR);

Any help?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/296425-undefined-function-trigger_error/
Share on other sites

Weird trigger_error is an internal php function, php -l does not flag up any such error here for me. :confused: . Strange it flagged the error on line 39. But you used that function on lines 8 and 20 previously

 

I'm guessing there is some weird whitespace character used in the indentation which is causing the function name to not be recognized. Does the error persist if you remove the indentation before calling the function and/or retyping the function name?

I'm guessing there is some weird whitespace character used in the indentation which is causing the function name to not be recognized. Does the error persist if you remove the indentation before calling the function and/or retyping the function name?

That. The rest of the indentation is 4 spaces but that line has 6, and the error message has a couple extra spaces before the function name.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.