gmc1103
Members-
Posts
251 -
Joined
-
Last visited
Everything posted by gmc1103
-
Yes because teh password is changed and like i told..i have this in my debugger <div class="alert alert-success">Verifique o seu mail....Obrigado</div> So it enters in the changePassword() function and the return is true
-
Hi Thank you The problem is they are not different page The newpass.php has thos code <?PHP error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); require_once("./include/membersite_config.php"); if (!$fgmembersite->CheckLogin()) { $fgmembersite->RedirectToURL("index.php"); exit; } if (isset($_POST['submitted'])) { if($fgmembersite->ChangePassword()){ $result = '<div class="alert alert-success">Password alterada com sucesso</div>'; sleep(2); $fgmembersite->RedirectToURL("index.php"); } else{ $result = '<div class="alert alert-danger">A mudança de password não foi efetuadada....tente mais tarde</div>'; } } $email = $fgmembersite->UserEmail(); ?> <html> <head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>EBSPMA Atividades</title> <link href="css/styles.css" rel="stylesheet"> <link href="css/bootstrap.min.css" rel="stylesheet"> <script src="js/modernizr.js?cb=2.2.3.2085"></script> <script type="text/javascript"> </script> </head> <body> <header role="banner" class="main-header"> <!-- MAIN HEADER --> <div class="main-header-body"> <div class="container-wrapper"> <div class="container-fluid"> <div class="row"> <div class="col-xs-3"> <h2>EBSPMA PAAD</h2> </div> <div class="col-xs-4 col-xs-offset-1 main-header-title"> <p class="sizeToggle" >Mudar Password</p> </div> </div> </div> </div> </div> </header><section class="content"> <div class="grid"> <div class="box"> <form name="changepwd" id="loginForm" action='<?php echo $fgmembersite->GetSelfScript(); ?>' method="POST"> <input type="hidden" name='submitted' id='submitted'/> <input type="hidden" name="path" value="painelAdquirente.action"/> <div> <p><b><font color="red">A sua password deve ser alterada!</font></b></p></div> <div class="icon-input"> <label for="password"></label> <div class="input password"> <i class="fa fa-lock"></i> <input type="password" name="oldpwd" id="oldpwd" placeholder="Senha antiga"> </div> </div> <br> <div class="icon-input"> <label for="password"></label> <div class="input password"> <i class="fa fa-lock"></i> <input type="password" name="newpwd" id="newpwd" placeholder="Senha nova"> </div> <input type="hidden" name="email" id="email" value="<?php echo $email; ?>"> </div> <br> <input type="submit" id="sbmtLogin" class="sa-btn1" value="Mudar"> </form> </div> <div class="form-group"> <?php echo $result; ?> </div> </div> </section> <script src="js/jquery-1.11.1.min.js"></script> <script src="js/jquery.validate.min.js"></script> <script src="js/plugins.js?cb=2.2.3.2085"></script> </body> </html> When i press the button it calls that function changePassword() and i have a return (true or false), since my return is always true it should work but it doesn't If i use this code... if (isset($_POST['submitted'])) { echo '<div class="alert alert-success">Password alterada com sucesso</div>'; sleep(2); if($fgmembersite->ChangePassword()){ $fgmembersite->RedirectToURL("index.php"); } echo '<div class="alert alert-danger">A mudança de password não foi efetuadada....tente mais tarde</div>'; sleep(2); } i get in my debugger...the echo "Password alterada com sucesso" but the div is not so the user can't see if the password has been changed.
-
Yes,,i know but why? if the function returns true i have a result and that result should be in that div. But when the page loads...i have this error at the beginning because it expects that variable. So what's wrong??
-
Yes This where is called from <?PHP error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); require_once("./include/membersite_config.php"); if (!$fgmembersite->CheckLogin()) { $fgmembersite->RedirectToURL("index.php"); exit; } if (isset($_POST['submitted'])) { if($fgmembersite->ChangePassword()){ $result = '<div class="alert alert-success">Password alterada com sucesso</div>'; sleep(2); $fgmembersite->RedirectToURL("index.php"); } else{ $result = '<div class="alert alert-danger">A mudança de password não foi efetuadada....tente mais tarde</div>'; } }} $email = $fgmembersite->UserEmail(); ?><html> <head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>EBSPMA Atividades</title> <link href="css/styles.css" rel="stylesheet"> <link href="css/bootstrap.min.css" rel="stylesheet"> <script src="js/modernizr.js?cb=2.2.3.2085"></script> <script type="text/javascript"> </script> </head> <body> <header role="banner" class="main-header"> <!-- MAIN HEADER --> <div class="main-header-body"> <div class="container-wrapper"> <div class="container-fluid"> <div class="row"> <div class="col-xs-3"> <h2>EBSPMA PAAD</h2> </div> <div class="col-xs-4 col-xs-offset-1 main-header-title"> <p class="sizeToggle" >Mudar Password</p> </div> </div> </div> </div> </div> </header><section class="content"> <div class="grid"> <div class="box"> <form name="changepwd" id="loginForm" action='<?php echo $fgmembersite->GetSelfScript(); ?>' method="POST"> <input type="hidden" name='submitted' id='submitted'/> <input type="hidden" name="path" value="painelAdquirente.action"/> <div> <p><b><font color="red">A sua password deve ser alterada!</font></b></p></div> <div class="icon-input"> <label for="password"></label> <div class="input password"> <i class="fa fa-lock"></i> <input type="password" name="oldpwd" id="oldpwd" placeholder="Senha antiga"> </div> </div> <br> <div class="icon-input"> <label for="password"></label> <div class="input password"> <i class="fa fa-lock"></i> <input type="password" name="newpwd" id="newpwd" placeholder="Senha nova"> </div> <input type="hidden" name="email" id="email" value="<?php echo $email; ?>"> </div> <br> <input type="submit" id="sbmtLogin" class="sa-btn1" value="Mudar"> </form> </div> </div> </section> <script src="js/jquery-1.11.1.min.js"></script> <script src="js/jquery.validate.min.js"></script> <script src="js/plugins.js?cb=2.2.3.2085"></script> </body> </html>
-
Hi Thanks for your reply This is the fucntion called from that piece of code function ChangePassword() { $email=trim($_POST['email']); if (!$this->CheckLogin()) { $this->HandleError("Não iniciou sessão!"); return false; } if (empty($_POST['oldpwd'])) { $this->HandleError("Password antiga vazia!"); return false; } if (empty($_POST['newpwd'])) { $this->HandleError("Nova password vazia!"); return false; } $user_rec = array(); if (!$this->GetUserFromEmail($this->UserEmail(), $user_rec)) { return false; } $pwd = trim($_POST['oldpwd']); $hash = md5($pwd); $nresult = mysqli_query($this->connection,"SELECT password FROM utilizador WHERE email = '$email'") or die(mysql_error()); $no_of_rows = mysqli_num_rows($nresult); if ($no_of_rows > 0) { $nresult = mysqli_fetch_array($nresult); $password = $nresult['password']; $password1 = md5($password); if ($password != $hash) { $this->HandleError("A password antiga não coincide com os nossos registos!"); return false; } } $newpwd = trim($_POST['newpwd']); if (!$this->ChangePasswordInDB($email, $newpwd)) { return false; } return true; } So, it the function returns true...it should be enought, no?
-
Hello I have this fucntion and is working well but my div are not showing if (isset($_POST['submitted'])) { if($fgmembersite->ChangePassword()){ $result = '<div class="alert alert-success">Password alterada com sucesso</div>'; sleep(2); $fgmembersite->RedirectToURL("index.php"); } else{ $result = '<div class="alert alert-danger">A mudança de password não foi efetuadada....tente mais tarde</div>'; } } I expected to get teh result here <div class="form-group"> <?php echo $result; ?> </div> i'm having this error Notice: Undefined variable: result in /home/ebspma/public_html/gesdocente/newpass.php on line 81 Any help please?
-
Thank you Psycho I didn't realise that i had to use of parenthesis I'm guessing i'm learning everyday with this forum. Thanks again
-
Hi Psycho Thanks for your answer Yes, i know i must always a value (0,1,2,3,etc) but in this case it should be 0 and i get 1 Comando SQL: SELECT COUNT(*) AS total FROM `ebspma_paad_ebspma`.`req_material_reserva` WHERE `idequipamento` is null or `idequipamento` = 12 AND `idsala` = 13 AND `idtempoInicio` < 2 AND `idTempoFim` > 2 AND `data` = "2015-06-12"; Registos: 1 total 1 And in my database i don't have i don't have any "idtempoInicio" with 2 and any "idTempoFim" with 2
-
Hi I'm looking to build an effective query but i'm having a problem. Barand suggest me this query SELECT COUNT(*) AS total FROM `ebspma_paad_ebspma`.`req_material_reserva` WHERE `idequipamento` = $equip AND `idsala` = $sala AND `idtempoInicio` < $fim AND `idTempoFim` > $inicio AND `data` = $data But i'm having this problem But with this query SELECT COUNT( * ) AS total FROM `ebspma_paad_ebspma`.`req_material_reserva` WHERE `idequipamento` IS NULL OR `idequipamento` =12 AND `idsala` =13 AND `idtempoInicio` <2 AND `idTempoFim` >2 AND `data` = "2015-06-12" I still have one result, but i don't have any "idtempoInicio" with 2 and any "idTempoFim" with 2 So the this query gives wrong result Any help
-
Hi I have a strange error in this code, the fisrt function works fine but the second one gives me "End of input character 0 of" <?php setlocale(LC_ALL, "pt_BR", "pt_BR.iso-8859-1", "pt_BR.utf-8", "portuguese"); if (isset($_POST['tag']) && $_POST['tag'] != '') { // tag escolhida $tag = filter_input(INPUT_POST, 'tag'); // inclui db handler require_once 'include/DB_Functions.php'; $db = new DB_Functions(); \mysql_query("SET NAMES 'utf8'"); $response = array("tag" => $tag, "success" => 0, "error" => 0); if ($tag == 'login') { $utilizador = filter_input(INPUT_POST, 'utilizador'); $password = filter_input(INPUT_POST, 'password'); $user = $db->getUserByNomeEPassword($utilizador, $password); if ($user != false) { $response["success"] = 1; $response["user"]["nome"] = $user["nome"]; $response["user"]["utilizador"] = $user["utilizador"]; $response["user"]["idutilizador"] = $user["idutilizador"]; $response["user"]["tipoutilizador_idtipoutilizador"] = $user["tipoutilizador_idtipoutilizador"]; echo json_encode($response); } else { $response["error"] = 0; $response["error_msg"] = "Utilizador ou password errados!"; echo json_encode($response); } } //Verificado if ($tag == 'reqSalasCheck') { $idUser = filter_input(INPUT_POST, 'idUser'); $sala = filter_input(INPUT_POST, 'sala'); $inicio = filter_input(INPUT_POST, 'inicio'); $fim = filter_input(INPUT_POST, 'fim'); $data = filter_input(INPUT_POST, 'dataFinal'); $dias = strftime('%A', strtotime($data)); $newDate = date("Y-m-d", strtotime($data)); $diaId = mysql_query("SELECT * FROM `ebspma_paad_ebspma`.`semana_dias` WHERE dia ='$dias'"); $diaRow = mysql_fetch_row($diaId)or die(mysql_error()); $Dias = $diaRow[0]; if ($Dias != null) { $inicioId = mysql_query("SELECT `idtempo` FROM `ebspma_paad_ebspma`.`req_material_tempo` WHERE `inicio`='$inicio'"); $inicioRow = mysql_fetch_row($inicioId)or die(mysql_error()); $inicio = $inicioRow[0]; if ($inicio != null) { $salaId = mysql_query("SELECT `idsala` FROM `ebspma_paad_ebspma`.`req_material_sala` WHERE `sala` = '$sala'"); $salaRow = mysql_fetch_row($salaId)or die(mysql_error()); $sala = $salaRow[0]; if ($sala != null) { $fimId = mysql_query("SELECT `idtempo` FROM `ebspma_paad_ebspma`.`req_material_tempo` WHERE `fim`= '$fim'"); $fimRow = mysql_fetch_row($fimId)or die(mysql_error()); if ($fim != null) { $checkIfOcupado = mysql_query("SELECT COUNT(id_dia) FROM `ebspma_paad_ebspma`. `sala_ocupacao` WHERE id_dia = '$Dias' AND id_sala= '$sala' AND id_tempo = '$inicio'"); $checkResult = mysql_fetch_row($checkIfOcupado) or die($checkIfOcupado . "<br/><br/>" . mysql_error()); $checkResultado = $checkResult[0]; if ($checkResultado > 0) { $response["error"] = 0; $response["error_msg"] = "Hora marcada no ano"; echo json_encode($response); } else { $checkIfReservado = mysql_query("SELECT COUNT(*) AS total FROM `ebspma_paad_ebspma`.`req_material_reserva` WHERE `ebspma_paad_ebspma`.`req_material_reserva`.`idsala` = '$sala' AND (((`req_material_reserva`.`idtempoInicio` BETWEEN '$inicio' AND '$fim') AND (`req_material_reserva`.`idTempoFim` BETWEEN '$inicio' AND '$fim')) OR (`req_material_reserva`.`idtempoInicio` <= '$inicio' AND `req_material_reserva`.`idTempoFim` >= '$fim')) AND `req_material_reserva`.`data` = '$newDate'"); $checkReserva = mysql_fetch_row($checkIfReservado) or die($checkIfReservado . "<br/><br/>" . mysql_error()); $checkReservado = $checkReserva[0]; if ($checkReservado > 0) { $response["error"] = 0; $response["error_msg"] = "Oops! Sala reservada"; echo json_encode($response); } else { $response["success"] = 1; $response["message"] = "Sala disponível."; echo json_encode($response); } } } } } } } if ($tag == 'checkEquipReserva') { $idUser = filter_input(INPUT_POST, 'idUser'); $sala = filter_input(INPUT_POST, 'sala'); $inicio = filter_input(INPUT_POST, 'inicio'); $fim = filter_input(INPUT_POST, 'fim'); $data = filter_input(INPUT_POST, 'dataFinal'); $dias = strftime('%A', strtotime($data)); $newDate = date("Y-m-d", strtotime($data)); $diaId = mysql_query("SELECT * FROM `ebspma_paad_ebspma`.`semana_dias` WHERE dia ='$dias'"); $diaRow = mysql_fetch_row($diaId)or die(mysql_error()); $Dias = $diaRow[0]; if ($Dias != null) { $inicioId = mysql_query("SELECT `idtempo` FROM `ebspma_paad_ebspma`.`req_material_tempo` WHERE `inicio`='$inicio'"); $inicioRow = mysql_fetch_row($inicioId)or die(mysql_error()); $inicio = $inicioRow[0]; if ($inicio != null) { $salaId = mysql_query("SELECT `idsala` FROM `ebspma_paad_ebspma`.`req_material_sala` WHERE `sala` = '$sala'"); $salaRow = mysql_fetch_row($salaId)or die(mysql_error()); $sala = $salaRow[0]; if ($sala != null) { $fimId = mysql_query("SELECT `idtempo` FROM `ebspma_paad_ebspma`.`req_material_tempo` WHERE `fim`= '$fim'"); $fimRow = mysql_fetch_row($fimId)or die(mysql_error()); if ($fim != null) { $checkIfOcupado = mysql_query("SELECT COUNT(id_dia) FROM `ebspma_paad_ebspma`. `sala_ocupacao` WHERE id_dia = '$Dias' AND id_sala= '$sala' AND id_tempo = '$inicio'"); $checkResult = mysql_fetch_row($checkIfOcupado) or die($checkIfOcupado . "<br/><br/>" . mysql_error()); $checkResultado = $checkResult[0]; if ($checkResultado > 0) { $response["error"] = 0; $response["error_msg"] = "Hora marcada no ano"; echo json_encode($response); } else { $checkIfReservado = mysql_query("SELECT COUNT(*) AS total FROM `ebspma_paad_ebspma`.`req_material_reserva` WHERE `ebspma_paad_ebspma`.`req_material_reserva`.`idsala` = '$sala' AND (((`req_material_reserva`.`idtempoInicio` BETWEEN '$inicio' AND '$fim') AND (`req_material_reserva`.`idTempoFim` BETWEEN '$inicio' AND '$fim')) OR (`req_material_reserva`.`idtempoInicio` <= '$inicio' AND `req_material_reserva`.`idTempoFim` >= '$fim')) AND `req_material_reserva`.`data` = '$newDate'"); $checkReserva = mysql_fetch_row($checkIfReservado) or die($checkIfReservado . "<br/><br/>" . mysql_error()); $checkReservado = $checkReserva[0]; if ($checkReservado > 0) { $response["error"] = 0; $response["error_msg"] = "Oops! Sala reservada"; echo json_encode($response); } else { $response["success"] = 1; $response["message"] = "Sala disponível."; echo json_encode($response); } } } } } } } } The first function works fine "reqSalasCheck" the second gives me tha error and they are equal....why? Regards
-
Hi Barand Thank you, really it was the problem. Thanks again Regards
-
Hi I have this php file with some queries but is acting strange because when the values are passed from a form everything is correct and the Select count should be 1 and gives 0 This the code <?php header('Content-Type: application/json'); error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); $mysqli = new mysqli('localhost', 'xxxxxx', 'xxxxx'); if (mysqli_connect_errno()) { trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR); } $iduser = filter_input(INPUT_POST, 'iduser'); $inicio = filter_input(INPUT_POST, 'inicio'); $fim = filter_input(INPUT_POST, 'fim'); $data = filter_input(INPUT_POST, 'data'); $equip = filter_input(INPUT_POST, 'equip'); $dia = filter_input(INPUT_POST, 'dia'); $sala = filter_input(INPUT_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) { echo json_encode(array('status' => 'error', 'message' => 'Oppss....Sala indisponível')); } else { $sql = "SELECT COUNT(*) AS total FROM `ebspma_paad_ebspma`.`req_material_reserva` WHERE `req_material_reserva`.`idequipamento` = ? AND `ebspma_paad_ebspma`.`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('iiiiiiiis', $equip, $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' => 'Oppss....equipamento ou sala indisponível')); } else{ echo json_encode(array('status' => 'success', 'message' => 'O equipamento está disponível')); } } The first query run with this values checkEquipLivre.php?iduser=1261&dia=1&sala=6&equip=16&inicio=1&fim=2&data=2015-06-15 And from my database, the values dia = 1, and sala = 6 and inicio = 1 gives me 1 SELECT COUNT( id_dia ) FROM `ebspma_paad_ebspma`.`sala_ocupacao` WHERE id_dia =1 AND id_sala =6 AND id_tempo =1 + Opções COUNT(id_dia) 1 And from my php file i have the response 0 Whats wrong?
-
Hi Does your HTML page have a <meta> tag where the charset attribute is set to "utf-8"? Yes, Encoding : UTF-8 If so, does your browser recognize the page encoding? Chrome (Automatic detection (UTF- Is PHP set to use UTF-8? <?php $mysqli = new mysqli('localhost', 'xxxxx', 'xxxxxx'); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } /* change character set to utf8 */ if (!$mysqli->set_charset("utf8")) { printf("Error loading character set utf8: %s\n", $mysqli->error); } else { printf("Current character set: %s\n", $mysqli->character_set_name()); } $mysqli->close(); ?> Response : Current character set: utf8 Is the MySQL connection object set to use UTF-8? I put this and now it works mysqli_set_charset($mysqli,"utf8"); The main problem now is i don't get the json_encode response into my <div> but in debugger is received Informação{"status":"success","message":"Nova formação gravada"} What's wrong here? <script type="text/javascript"> $(document).ready(function () { $("#formacao").submit(function (e) { e.preventDefault(); var formData = new FormData($(this)[0]); $.ajax({ url: 'nova_formacaoBD.php', type: 'POST', data: formData, cache: false, contentType: false, processData: false, beforeSend: function () { $('#ajaxDivAlert').show().html('A carregar o ficheiro...aguarde por favor'); } }).done(function (data) { var result = data.status; if (result === 'success'){ $('#ajaxDivAlert').fadeOut(); $('#ajaxDivOk').show().html('Informação: ' + data.message); $("#ajaxDivOk").fadeOut(5000); } }).fail(function (data) { var result = data.status; if (result === 'error'){ $("#ajaxDivErro").html('Informação: ' + data.message); $("#ajaxDivErro").fadeIn(); $("#ajaxDivErro").fadeOut(5000); } }); }); }); </script> Any error?
-
My form has utf-8 And the database has utf-8 generic So i don't get whats wrong
-
Hi I have defined my database as utf-8 but when i insert i get strange character inserted This is my ajax form <script type="text/javascript"> $(document).ready(function () { $("#formacao").submit(function (e) { e.preventDefault(); var formData = new FormData($(this)[0]); $.ajax({ url: 'nova_formacaoBD.php', type: 'POST', data: formData, cache: false, contentType: false, processData: false, beforeSend: function () { $('#ajaxDivAlert').show().html('A carregar o ficheiro...aguarde por favor'); } }).done(function (data) { var result = data.status; if (result == 'success'){ $('#ajaxDivAlert').fadeOut(); $('#ajaxDivOk').show().html('Informação: ' + data.message); $("#ajaxDivOk").fadeOut(5000); } }).fail(function (data) { var result = data.status; if (result == 'error'){ $("#ajaxDivErro").html('Informação: ' + data.message); $("#ajaxDivErro").fadeIn(); $("#ajaxDivErro").fadeOut(5000); } }); }); }); And this is insert php <?php header('Content-Type: application/json'); error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); $mysqli = new mysqli('localhost', 'xxxxx', 'xxxxx'); if (mysqli_connect_errno()) { trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR); } $uploaddir = $_SERVER['DOCUMENT_ROOT'] . '/uploads'; $uploadfile = $uploaddir . '/' . basename($_FILES['fileToUpload']['name']); $escola = filter_input(INPUT_POST, 'escola'); $form = filter_input(INPUT_POST, 'form'); $data =filter_input(INPUT_POST, 'data'); $horas = filter_input(INPUT_POST, 'horas'); $local = filter_input(INPUT_POST, 'local'); $dest = filter_input(INPUT_POST, 'dest'); $datas = filter_input(INPUT_POST, 'datas'); $visto = 0; echo $form; if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $uploadfile)) { $target_path = "/uploads/" . basename($_FILES['fileToUpload']['name']); $sql = "INSERT INTO `ebspma_paad_ebspma`.`formacoes`(idescola, nome, inicio, horas, local, destinatarios, dataLimite, visto, path) VALUES(?, ?, ?, ?, ? ,?, ?, ?, ? )"; $stmt = $mysqli->prepare($sql); if ($stmt === false) { trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $mysqli->error, E_USER_ERROR); } $stmt->bind_param('issssssis', $escola, $form, $data, $horas, $local, $dest, $datas, $visto, $target_path); if (!$stmt->execute()) { echo json_encode(array('status' => 'error', 'message' => 'Opppss...A formação não foi gravada')); } } else { echo json_encode(array('status' => 'error', 'message' => 'Opppss...A formação não foi gravada')); } $stmt->close(); echo json_encode(array('status' => 'success', 'message' => 'Nova formação gravada')); The word inserted is Informação instead of Informação And the strange is i don't get in my <div> the result but in debugger i see Informação{"status":"success","message":"Nova formação gravada"} Whats wrong?
-
And this is my form <form action="nova_formacaoBD.php" method="post" id="formacao" name="formacao" enctype="multipart/form-data"> <div class="form-group"> <label for="exampleInputFile">Escola: </label> <select class="form-control" id="escola" name="escola" onchange="verificaEscola()"> <?php echo $escolaOptions; ?> </select> </div> <div class="form-group"> <div id="ajaxDivErroEscola" style="display:none" class="alert alert-danger"></div> </div> <div class="form-group"> <label for="exampleInputEmail1">Nome Formação: </label> <input class="form-control" id="form" name="form" onchange="verificaNome()"> </input> </div> <div class="form-group"> <div id="ajaxDivErroForm" style="display:none" class="alert alert-danger"></div> </div> <div class="form-group"> <label for="exampleInputEmail1">Data de Início: </label><input type="text" class="form-control" id="data" name="data" onchange="verificaData()" /> </div> <div class="form-group"> <div id="ajaxDivErroData" style="display:none" class="alert alert-danger"></div> </div> <div class="form-group"> <label for="exampleInputEmail1">Horas: </label><input type="text" class="form-control" id="horas" name="horas" onchange="verificaHoras()"> </div> <div class="form-group"> <div id="ajaxDivErroHoras" style="display:none" class="alert alert-danger"></div> </div> <div class="form-group"> <label for="exampleInputEmail1">Local: </label> <input class="form-control" id="local" name="local" onchange="verificaLocal()"> </input> </div> <div class="form-group"> <div id="ajaxDivErroLocal" style="display:none" class="alert alert-danger"></div> </div> <div class="form-group"> <label for="exampleInputEmail1">Destinatários: </label> <input class="form-control" id="dest" name="dest" onchange="verificaDest()"> </input> </div> <div class="form-group"> <div id="ajaxDivErroDest" style="display:none" class="alert alert-danger"></div> </div> <div class="form-group"> <label for="exampleInputEmail1">Data Limite: </label><input type="text" class="form-control" id="datas" name="datas" onchange="verificaDataLimite()"/> </div> <div class="form-group"> <div id="ajaxDivErroDataLimite" style="display:none" class="alert alert-danger"></div> </div> <div class="form-group"> <label for="exampleInputFile">Programa da Formação</label> <input type="file" name="fileToUpload" id="fileToUpload" name="fileToUpload"> </div> <div class="form-group"> <div id="ajaxDivErroFile" style="display:none" class="alert alert-danger"></div> </div> <div class="form-group"> <div id="ajaxDivOk" style="display:none" class="alert alert-success">Aqui</div> </div> <div class="form-group"> <div id="ajaxDivErro" style="display:none" class="alert alert-danger"></div> </div> <button type="submit" class="btn btn-default" onclick="return checkBoxes(this)">Registar</button> </form>
-
Hi This is the response in console {"status":"success","message":"Nova forma\u00e7\u00e3o gravada"} So i receive the the json array The problem is i don't stay in my page form (/superNewFormacao.php) and i get the response from my insert php file (nova_formacaoBD.php) This is my php <?php header('Content-Type: application/json'); error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); $mysqli = new mysqli('localhost', 'xxxxxx', 'xxxxxxx'); if (mysqli_connect_errno()) { trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR); } $uploaddir = $_SERVER['DOCUMENT_ROOT'] . '/uploads'; $uploadfile = $uploaddir . '/' . basename($_FILES['fileToUpload']['name']); $escola = $_POST['escola']; $form = $_POST['form']; $data = $_POST['data']; $horas = $_POST['horas']; $local = $_POST['local']; $dest = $_POST['dest']; $datas = $_POST['datas']; $visto = 0; if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $uploadfile)) { $target_path = "/uploads/" . basename($_FILES['fileToUpload']['name']); $sql = "INSERT INTO `ebspma_paad_ebspma`.`formacoes`(idescola, nome, inicio, horas, local, destinatarios, dataLimite, visto, path) VALUES(?, ?, ?, ?, ? ,?, ?, ?, ? )"; $stmt = $mysqli->prepare($sql); if ($stmt === false) { trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $mysqli->error, E_USER_ERROR); } $stmt->bind_param('issssssis', $escola, $form, $data, $horas, $local, $dest, $datas, $visto, $target_path); if (!$stmt->execute()) { echo json_encode(array('status' => 'error', 'message' => 'Opppss...A formação não foi gravada')); } } else { echo json_encode(array('status' => 'error', 'message' => 'Opppss...A formação não foi gravada')); } $stmt->close(); echo json_encode(array('status' => 'success', 'message' => 'Nova formação gravada'));
-
In console i don't get anything but i receive the json response in the browser in json format
-
Hi I'm having problem (no response is received in my html page) with ajax This is the php with echo echo json_encode(array('status' => 'success', 'message' => 'Nova formação gravada')); And this is my ajax <script type="text/javascript"> $.ajax({ url: 'nova_formacaoBD.php', data: { format: 'json' }, error: function() { $("#ajaxDivErro").html('Esta formação já está registada na base de dados'); }, dataType: 'json', success: function(data) { $('#ajaxDivOk').html('Informação: Esta formação foi registada na base de dados'); }, type: 'GET' }); </script> So after inserting the data into my database i would like to receive the response to a div. Whats wrong? Thanks
-
Hi Thank you, this was the problem, but now i'm facing another one with this code I have this $target_dir = $dirpath ."/uploads/"; But what i get saved into my database is /home/ebspma/public_htmlhtml> and it should be http://ebsp.comt/uploads/filename What is wrong with my code?
-
Hi I'm trying to upload a file into my server and save the url path into my database <?php header('Content-Type: application/json'); error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); $mysqli = new mysqli('localhost', 'xxxxx', 'xxxxxx'); if (mysqli_connect_errno()) { trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR); } $dirpath = realpath(dirname(getcwd())); $target_dir = $dirpath ."/uploads/"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $Filename= addslashes(file_get_contents($_FILES['fileToUpload']['tmp_name'])); $file_path = $dirpath.basename($Filename); $escola = $_POST['escola']; $form = $_POST['form']; $data = $_POST['data']; $horas = $_POST['horas']; $local = $_POST['local']; $dest = $_POST['dest']; $datas = $_POST['datas']; $visto = 0; if(move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target_file)) { $sql = "INSERT INTO `ebspma_paad_ebspma`.`formacoes`(idescola, nome, inicio, horas, local, destinatarios, dataLimite, visto, path) VALUES(?, ?, ?, ?, ? ,?, ?, ?, ? )"; $stmt = $mysqli->prepare($sql); if ($stmt === false) { trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $mysqli->error, E_USER_ERROR); } $stmt->bind_param('issssssib', $escola, $form, $data, $horas,$local,$dest, $datas, $visto, $file_path ); if (!$stmt->execute()) { echo json_encode(array('status' => 'error', 'message' => 'Opppss...A formação não foi gravada')); } } else { echo json_encode(array('status' => 'error', 'message' => 'Opppss...A formação não foi gravada')); } $stmt->close(); echo json_encode(array('status' => 'success', 'message' => 'Nova formação gravada')); The file is saved into my server but the path is not saved into my database.... whats wrong? Thanks
-
Hi Good morning. Yes, it was the indentation. Best regards and Thank you
-
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
-
It works like a charm Thank you for your example and help Best regards
-
I do that with getSalas.php? Never did, i need one example can you show me one? Regards and Thank you