Jump to content

undefined function trigger_error()


Go to solution Solved by Ch0cu3r,

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

  • Solution

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?

  • Like 1

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.