gmc1103 Posted May 20, 2015 Share Posted May 20, 2015 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 Quote Link to comment https://forums.phpfreaks.com/topic/296425-undefined-function-trigger_error/ Share on other sites More sharing options...
Solution Ch0cu3r Posted May 20, 2015 Solution Share Posted May 20, 2015 Weird trigger_error is an internal php function, php -l does not flag up any such error here for me. . 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? 1 Quote Link to comment https://forums.phpfreaks.com/topic/296425-undefined-function-trigger_error/#findComment-1512329 Share on other sites More sharing options...
requinix Posted May 20, 2015 Share Posted May 20, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/296425-undefined-function-trigger_error/#findComment-1512341 Share on other sites More sharing options...
gmc1103 Posted May 21, 2015 Author Share Posted May 21, 2015 Hi Good morning. Yes, it was the indentation. Best regards and Thank you Quote Link to comment https://forums.phpfreaks.com/topic/296425-undefined-function-trigger_error/#findComment-1512381 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.