Jump to content

gmc1103

Members
  • Posts

    258
  • Joined

  • Last visited

Everything posted by gmc1103

  1. Hi Barand i have removed this line print_r($this->db->query($sql)); and i don't have that error again but i have a strange situation From my sqlyog i use this DELETE FROM `esmaior_biblioteca`.`item` WHERE `id_itens` = "6"; and it works in the code i put a line to check if i receive the var and i have result (11) print_r($id_itens); 4a "11"{"status":"success","message":"O registo foi removido com sucesso..."} 0 And it say removed but when i check it still in my database..
  2. Hi I'm having an error in the following code and i don't get why public function delItem($id_itens){ try { $sql = 'DELETE FROM `item` WHERE `id_itens`=:me'; $stmt = $this->db->prepare($sql); $stmt->bindValue(':me', $id_itens, PDO::PARAM_STR); if (!$stmt->execute()) { print_r($stmt->errorInfo()); return array('status' => 'error', 'message' => 'Problema ao remover este item...'); } else { print_r($this->db->query($sql)); return array('status' => 'success', 'message' => 'O registo foi removido com sucesso...'); } } catch (PDOException $e) { echo $e->getMessage(); } } and the error is SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':me' at line 1
  3. Hi Barand Thank you Made a few change now no error but no data too $query = 'SELECT t1.id_plano , t2.cargo , t1.atividade , t1.descricao , t1.obj , t1.periodo , t1.previsao , t1.data_prevista , t1.orcamento , t1.destinatarios, t1.observacoes FROM new_pae AS t1 INNER JOIN pae_cargo AS t2 ON (t1.id_cargo=t2.idcargo) where t1.periodo = :me ORDER BY data_prevista ASC'; $stmt = $DB_con->prepare($query); if (!$stmt) { echo "\nPDO::errorInfo():\n"; print_r($DB_con->errorInfo()); } $stmt->bindparam(":me", $search,PDO::PARAM_STR); $stmt->execute(); $ixx = 0; while($result = $stmt->fetchAll(PDO::FETCH_ASSOC)){ $ixx = $ixx+1; $data_chegada[] = array_merge($result, array('num'=>$ixx)); } Since this is a pdf, how can i check if the $data_chegada array is not empty?
  4. I used pdo like suggested but i'm stuck again try { $DB_con = new PDO("mysql:host={$DB_host};dbname={$DB_name}",$DB_user,$DB_pass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); $DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e) { echo $e->getMessage(); } $query = $DB_con->query("SELECT t1.id_plano , t2.cargo , t1.atividade , t1.descricao , t1.obj , t1.periodo , t1.previsao , t1.data_prevista , t1.orcamento , t1.destinatarios, t1.observacoes FROM new_pae AS t1 INNER JOIN pae_cargo AS t2 ON (t1.id_cargo=t2.idcargo) t1.periodo =:me ORDER BY data_prevista ASC"); $query->$DB_con->prepare($sql); if (!$query) { echo "\nPDO::errorInfo():\n"; print_r($DB_con->errorInfo()); } $query->bindparam(":me", $search,PDO::PARAM_STR); $fetch = $query->fetchAll(); $query->bind_result($id_plano, $cargo, $atividade, $descricao, $obj, $periodo, $previsao, $data, $orcamento, $destinarios, $observacoes); $ixx = 0; foreach ($fetch as $plano) { $ixx = $ixx+1; $data_chegada[] = array_merge($plano, array('num'=>$ixx)); } Now the error is Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't1.periodo =:me ORDER BY data_prevista ASC' at line 2' So my sql syntax have error but i can't see anyone
  5. Hi mac_gyver Thank you, so if i undertstood what you told I used stmt->bind_param('s', $search); $stmt->execute(); $result = $stmt->get_result(); $stmt->bind_result($id_plano, $cargo, $atividade, $descricao, $obj, $periodo, $previsao, $data, $orcamento, $destinarios, $observacoes); while ($row = $result->fetch_array(MYSQLI_NUM)) { $ixx = 0; foreach ($row as $r) { $ixx = $ixx+1; $data_chegada[] = array_merge($r, array('num'=>$ixx)); } } and now i have Fatal error: Call to undefined method mysqli_stmt::get_result()
  6. Hi Thanks for your help The same error Warning: array_merge(): Argument #1 is not an array in while ($datatmp = $stmt ->fetch()) { $ixx = $ixx+1; $data_chegada[] = array_merge($datatmp, array('num'=>$ixx)); }
  7. I told i want to update to mysqli This is mysqli $mysqli = new mysqli('localhost', 'xxxx', 'xxxxx', 'xxxxxx'); if (mysqli_connect_errno()) { trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR); } mysqli_set_charset($mysqli,"utf8"); $sql = "SELECT t1.`id_plano` , t2.`cargo` , t1.`atividade` , t1.`descricao` , t1.`obj` , t1.`periodo` , t1.`previsao` , t1.`data_prevista` , t1.`orcamento` , t1.`destinatarios`, t1.`observacoes` FROM `new_pae` AS t1 INNER JOIN `pae_cargo` AS t2 ON ( t1.`id_cargo` = t2.`idcargo` ) where t1.`periodo` = ? ORDER BY `data_prevista` ASC "; $stmt = $mysqli->prepare($sql); if ($stmt === false) { trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $mysqli->error, E_USER_ERROR); } $stmt->bind_param('s', $search); $stmt->execute(); $stmt->bind_result($id_plano, $cargo, $atividade, $descricao, $obj, $periodo, $previsao, $data, $orcamento, $destinarios, $observacoes); $ixx = 0; while ($datatmp = $stmt ->fetch()) { $ixx = $ixx+1; $data_chegada[] = array_merge($stmt, array('num'=>$ixx)); } and the error is: Warning: array_merge(): Argument #1 is not an array i this line $data_chegada[] = array_merge($stmt, array('num'=>$ixx)); any help?
  8. Hi I'm trying to update my queries to mysqli but i'm having a lot of problems and i can't get them to work using this. This is my mysql usage $conexion = mysql_connect("localhost", "xxxxx", "xxxxx"); mysql_select_db("xxxxx", $conexion); $queEmp = "SELECT t1.`id_plano` , t2.`cargo` , t1.`atividade` , t1.`descricao` , t1.`obj` , t1.`periodo` , t1.`previsao` , t1.`data_prevista` , t1.`orcamento` , t1.`destinatarios`, t1.`observacoes` FROM `new_pae` AS t1 INNER JOIN `pae_cargo` AS t2 ON ( t1.`id_cargo` = t2.`idcargo` ) where t1.`periodo` = '$search' ORDER BY `data_prevista` ASC" ; mysql_query ("set character_set_client='utf8'"); $resEmp = mysql_query($queEmp, $conexion) or die(mysql_error()); $totEmp = mysql_num_rows($resEmp); if($totEmp<=0){ $sem = utf8_decode("<b>Não existem registos</b>\n"); $pdf->setColor(1, 0, 0); $pdf->addText(210, 669, 12, $sem); } $ixx = 0; while($datatmp = mysql_fetch_assoc($resEmp)) { $ixx = $ixx+1; $data_chegada[] = array_merge($datatmp, array('num'=>$ixx)); } The main problem is when i'm trying to put everything in the array and then use array_merge.. Anyone can point me to the right solution? Thanks
  9. Ok, il will try the first example you gave me. only one id and quantity, then a query to check if that book (school book) is borrow and how many has been borrowed by this user to his class. I will let you know if i'm stuck... Thank you for your help. Best regards
  10. Hi mac_gyver Thanks again for your explanation. I think i'm making a big confusion here. Your question why are you storing the quantity in each row? I don't want to store the full quantity in each row, just 1 in each what data do you want to store in each row? I want to store the book_id, name, year, quantity finally, for what purpose are you doing this? if this if for an inventory system, you would want a single row holding the quantity, not a separate row for each copy of a book. Again you are right But for instance, if someone of total of 12 get 10 copy, how can i know that i have 2 to borrow? Thanks again
  11. Hi Thanks for your contribution with var_dump i have string 'Livros' (length=6) array (size=1) 0 => string '12' (length=2) Is not correct?
  12. Hi Can someone help me with this function public function testes($livro, $quant) { try { $sql = 'INSERT INTO itens(livro, quant) VALUES '; $qPart = array_fill(count($livro), count($quant), "(?, ?)"); $sql .= implode(",",$qPart); $stmt = $this->db->prepare($sql); $i = 1; foreach($quant as $item) { $stmt -> bindParam($i++, $item['livro']); $stmt -> bindParam($i++, $item['quant']); } $stmt -> execute(); return $stmt; } catch (PDOException $e) { echo $e->getMessage(); } } And i have this error Warning: Illegal string offset 'livro' in C:\xampp\htdocs\esmaior_biblio\class.user.php on line 112 Fatal error: Only variables can be passed by reference 112 $stmt -> bindParam($i++, $item['livro']); Livro is book and quant is quantity If someone register a book and this book has 30 copy i want to use this function to insert 30 record of this book. What's wrong?
  13. Thank you both of you. Learning everyday with you guys. Best regards
  14. Thanks for helping me Ok, but now i have those dates 0000-00-00 , how can i avoid them in select query?
  15. Hi I'm having a problem with this query, it was good until the user starting to put 0000-00-00 SELECT t1.`id_plano`, t1.`atividade`, t1.`data_prevista` FROM `new_pae` AS t1 WHERE t1.`id_user` = '$idUser' AND t1.`data_prevista` <= CURDATE() AND (t1.`realizado` IS NULL OR LENGTH(t1.`realizado` ) =0) Now i trying to modfy this query to avoid this kind of date but i don't get it. This is an example how it comes id_plano atividade data_prevista -------- ------------------------------------------- --------------- 168 ''O Eco-Clube Informa'' 0000-00-00 169 Campanhas de recolha de materiais 0000-00-00 170 Campanha de recolha de ROUPAS E CALÇADO 0000-00-00 181 ''Pour un noel écolo!'' 2015-10-20 184 ''Pour un noel écolo!'' 0000-00-00 185 Visita de Estudo a uma Produção Agrícola 0000-00-00 186 Decorações de Natal 0000-00-00 187 Exposição/Concurso 0000-00-00 188 ECO-CRIATIVO 0000-00-00 189 Dia ECO-ESCOLA 0000-00-00 190 Exposição 0000-00-00 191 Workshop's 0000-00-00 192 Exposição 0000-00-00 193 Criação/construção de cenários 0000-00-00 The date 0000-00-00 is set when the user don't know when he gonna make that activity. Any help Thanks
  16. Thanks Psycho You are the man...Thank you, learning everyday.
  17. Hi I'm having a problem getting the user_id into a table td This is my php <?php if (empty($results)) { } else { foreach ($results as $row) { echo "<tr><td>"; echo $row['user_nome']; echo "</td><td>"; echo $row['user_email']; echo "</td><td>"; echo $row['user_tel']; echo '<td><a data-toggle="modal" data-id="echo $row['user_id']" class="open-AddDialog btn btn-sm btn-danger center-block" href="#myModal">Validar</a></td>'; } } ?> Giving me error in this line echo '<td><a data-toggle="modal" data-id="echo $row['user_id']" class="open-AddDialog btn btn-sm btn-danger center-block" href="#myModal">Validar</a></td>'; unexpected echo
  18. Hi Barand Thanks, the problem is with sqlyog i did a refresh in database and i had 0 booking but the query in the website was giving 1.....strange
  19. This is my sql dump http://ebspma.edu.pt/database.sql mac_gyver I'm lost with your question now...sorry I wnat to check if i have a booking in that classroom, and this date and time...
  20. Hi Barand I'm running the query in phpmyadmin and the result is to check if i can make a booking or not (0 - yes) (1- no)
  21. Hi I'm having a strange error regarding the following query SELECT COUNT(*) AS total FROM `ebspma_paad_ebspma`.`req_material_reserva` WHERE `ebspma_paad_ebspma`.`req_material_reserva`.`idsala` = 61 AND (((`ebspma_paad_ebspma`.`req_material_reserva`.`idtempoInicio` BETWEEN 3 AND 3) AND (`ebspma_paad_ebspma`.`req_material_reserva`.`idTempoFim` BETWEEN 3 AND 3)) OR (`ebspma_paad_ebspma`.`req_material_reserva`.`idtempoInicio` <= 3 AND `ebspma_paad_ebspma`.`req_material_reserva`.`idTempoFim` >= 3)) AND `ebspma_paad_ebspma`.`req_material_reserva`.`data` = "2015-10-23" The count gives me one but my table is empty... idreserva idutilizador idsala idtempoInicio idtempoFim idequipamento data --------- ------------ ------ ------------- ---------- ------------- ------------ Fields translation id_booking, id:user, id_classroom, id_initialtime(timestamp), id_finaltime(timestamp), id_equipment, date So what's wrong?? Thanks
  22. Hi Thank you for your help Now i'm able to write in my database but i don't receive any alert This is my update.php file <?php require_once("./include/fg_membersite.php"); $ebspma = new EBSPMA(); $ebspma->InitDB('localhost','xxxxx','xxxxx','xxxx'); if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { $result = $ebspma->visitaValidacaoByUserAdmin($_POST['userid'], $_POST['id_visita'], $_POST['plano'], $_POST['valido'] ); echo $result; } ?> and my ajax call <script> function submitForm2(formId){ var userid = '<?php echo $ebspma->UserId(); ?>'; var id_visita = $('input[id="id_visita"]').val(); var plano = $('input[id="plano"]').val(); var valido = $('input[id="valido"]').val(); $.ajax({ url: 'updates.php', type: 'POST', data : {'userid': userid, 'id_visita': id_visita, 'plano': plano, 'valido': valido}, dataType: 'json', success:function(response){ alert(response.message); $("#myModal2").modal('hide'); window.location.reload(true); } }); } </script> The function called is this one function visitaValidacaoByUserAdmin($userid, $id_visita, $plano, $valido) { $id = $this->SanitizeForSQL($userid); $planos = $this->SanitizeForSQL($plano); $validos = $this->SanitizeForSQL($valido); $sql = "UPDATE `new_visitas` SET `plano`= ?,`valido`= ? WHERE `id_visita` = ?"; $stmt = $this->connection->prepare($sql); if ($stmt === false) { trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $this->connection->error, E_USER_ERROR); } $stmt->bind_param('ssi',$planos, $validos, $id_visita); if (!$stmt->execute()) { echo json_encode(array('status' => 'error', 'message' => 'Opppss...A visita ainda não foi validada')); } else { echo json_encode(array('status' => 'success', 'message' => 'A visita já foi validada...Obrigado')); } $this->connection->close(); } In my console i receive this echo echo json_encode(array('status' => 'success', 'message' => 'A visita já foi validada...Obrigado')); {"status":"success","message":"A visita j\u00e1 foi validada...Obrigado"} But i have i no alert in my main page....any help? And if in updates.php i want to put different fucntions, how can i do it? Thanks again
  23. Hi I'm trying to call this following php function from a ajax call but i can't get it to work class EBSPMA { function visitaValidacaoByUserAdmin($userid) { if(isset($_POST['action']) && !empty($_POST['action'])) { $id_visita = filter_input(INPUT_POST, 'id_visita'); $plano =filter_input(INPUT_POST, 'plano '); $valido = filter_input(INPUT_POST, 'valido'); $sql = "UPDATE `new_visitas` SET `plano`= ?,`valido`= ? WHERE `id_visita` = ?"; $stmt = $this->connection->prepare($sql); if ($stmt === false) { trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $mysqli->error, E_USER_ERROR); } $stmt->bind_param('ssi',$plano, $valido, $id_visita); if (!$stmt->execute()) { echo json_encode(array('status' => 'error', 'message' => 'Opppss...A visita ainda não foi validada')); } else { echo json_encode(array('status' => 'success', 'message' => 'A visita já foi validada...Obrigado')); } $this->connection->close(); } } } and this is my ajax call function submitForm2(formId){ var id_visita = $('input[id="id_visita"]').val(); var plano = $('input[id="plano"]').val(); var valido = $('input[id="valido"]').val(); $.ajax({ url: 'include/fg_membersite.php', type: 'POST', data : {action: 'visitaValidacaoByUserAdmin()', 'id_visita': id_visita, 'plano': plano, 'valido': valido}, dataType: 'json', success:function(response){ alert(response.message); $("#myModal2").modal('hide'); window.location.reload(true); } }); } Nothing happens....any help please??
  24. Hi I have a strange error with tthis code, I have 2 functions one works well the other gives me that error function CheckAtividadesStatus(){ $sqlAtividadesStatus = "SELECT COUNT( * ) AS total FROM `nem_pae_atividades` WHERE `data` = CURDATE()"; $stmt = $this->connection->prepare($sqlAtividadesStatus); var_dump($stmt); if ($stmt === false) { trigger_error('Wrong SQL: ' . $sqlAtividadesStatus . ' Error: ' . $this->connection->error, E_USER_ERROR); } $stmt->execute(); $stmt->bind_result($total); $stmt->fetch(); $stmt->close(); if ($total != 0) { return false; } else{ return true; } $this->connection->close(); } function checkAtividadeFeita($userid) { $id = $this->SanitizeForSQL($userid); $sql = "SELECT COUNT( * ) AS total FROM `nem_pae_atividades` WHERE `idutilizador` = '$id' AND `data` <= CURDATE( ) AND (`realizado` IS NULL OR LENGTH(`realizado`)=0)"; $stmt = $this->connection->prepare($sql); if ($stmt === false) { trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $this->connection->error, E_USER_ERROR); } $stmt->execute(); $stmt->bind_result($total); $stmt->fetch(); $stmt->close(); if ($total != 0) { return false; } else{ return true; } $this->connection->close(); } As everyone can see they are almost the same but the queries are different The function CheckAtividadesStatus() gives me "Fatal error: Call to a member function prepare() on a non-object" in line $stmt = $this->connection->prepare($sqlAtividadesStatus); The other function works normally, so what's wrong? Thanks
  25. Hi Barand Thank you, iv'e tried the way you told me with no success This is what i have in my db So my point is the make the owner change the field "realizado" if the "data" has been reached My last query was SELECT COUNT( * ) AS total FROM `nem_pae_atividades` WHERE ( `idutilizador` =1355 AND `data` >= CURDATE( ) ) OR ( `realizado` IS NULL OR LENGTH( `realizado` ) ) =0
×
×
  • 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.