Jump to content

magcr23

Members
  • Posts

    80
  • Joined

  • Last visited

Everything posted by magcr23

  1. Maybee the URL option, but i don't have many experience with that, i get a litle confused after a few lines of code... but it's the only one i've already used. Wich one do you advise?
  2. Hi guys, i have this code: <ol class="breadcrumb"> <li class="active"> <a href="#">Back</a> </li> </ol> </div> </div> <div class="row"> <?php include("conexao.php"); ?> <?php $utilizador = $_SESSION["user"]; $mensagem=$_GET['mensagem']; $result = mysqli_query($con, "SELECT * FROM mensagens WHERE emissor = '$utilizador' AND id= $mensagem"); $ln = mysqli_fetch_assoc($result); echo 'De: ' . $ln['emissor'] . '<br/>'; echo 'Assunto: ' . $ln['assunto'] . '<br />'; echo 'Mensagem: ' . $ln['mensagem'] . '<br />'; ?> I want to change that: <ol class="breadcrumb"> <li class="active"> <a href="#">Back</a> </li> </ol> I have 3 pages: pag1, pag2, function I want it to do that, if the user was on pag1.php and came to function the link is <a href="pag1.php">Back</a> if the user was on pag2 and came to function the link is <a href="pag2.php">Back</a> How can i do that?
  3. As i said before i'm new with MySQLi, just trying to understand it better and learn what is possible do with it and how. Thx for your help
  4. I can't create a function like i did before?
  5. I had mysql_real_scape_string: <?php function limpa($valor){ return (mysql_real_escape_string(stripslashes($valor))); } ?> I'm converting all the website to mysqli, and i took the function off to be easly to search for errors. In the end i'll place them all. Thx for your help, with that $update= "UPDATE avaliacao SET nota = '{$nota}' , comentario = '{$comentario}' WHERE id = '{$id}'"; thx QuickOldCar. BTW, if you could convert my mysql_real_scape_string to mysqli would be great. Do i need only to place the i?? (mysql-->mysqli or do i need something else? I'm realy new in MySQLi...
  6. Ho guys, i have one page where i choose witch iten i want to update, and when the user press "alterar" it redirect to another page where there's a form that show's the values in database and let the user decide what he want update. But the update is not working. There's the code of the 2 pages: avaliacaoAlterar.php <?php require "verificauser.php"; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content=""> <meta name="author" content=""> <title>Alterar Avaliações</title> <!-- Bootstrap Core CSS --> <link href="css/bootstrap.min.css" rel="stylesheet"> <!-- Custom CSS --> <link href="css/sb-admin.css" rel="stylesheet"> <!-- Morris Charts CSS --> <link href="css/plugins/morris.css" rel="stylesheet"> <!-- Custom Fonts --> <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"> </head> <body> <div id="wrapper"> <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation"> <?php include("menuLateral.php"); include("menuTop.php"); ?> </nav> <div id="page-wrapper"> <div class="container-fluid"> <div class="row"> <div class="col-lg-12"> <div class="alert alert-info alert-dismissable"> <a href="avaliacao.php"> Avaliações Recentes</a> || <a href="avaliacaoPermitida.php">Avaliações Permitidas</a> || <a href="avaliacaoAlterar.php">Alterar Avaliações</a> </div> </div> </div> <?php $con=mysqli_connect("localhost","root","6794","website"); if (mysqli_connect_errno()){ echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $query = mysqli_query($con, "SELECT * FROM `avaliacao` "); $ln = mysqli_fetch_array($query); $avaliacao=$_GET['avaliacao']; $query2 = mysqli_query($con, "SELECT * FROM `avaliacao` WHERE id = $avaliacao"); $row = mysqli_fetch_array($query2); ?> <div id="page-wrapper"> <div class="container-fluid"> <table> <form action="alterar.php" method="POST"> <tr> <td>Número <input type="number" max="10" name="id" id="id" value='<?php echo $avaliacao ?>' required></td> </tr> <tr> <td> </td> </tr> <tr> <td>Nota <input type="number" name="nota" id="nota" value='<?php echo $row['nota']; ?>' required></td> </tr> <tr> <td> </td> </tr> <tr> <td>Comentário <textarea name="comentario" id="comentario" rows="1" cols="22" required><?php echo $row['comentario']; ?></textarea></td> </tr> <tr> <td> </td> </tr> <tr> <td><input type="submit" name="alterarAvaliacao" id="alterarAvaliacao"> </td> </tr> </form> </table> </div> </div> <?php mysqli_close($con); ?> </body> </html> alterar.php <?php $con=mysqli_connect("localhost","root","6794","website"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $id = $_POST["id"]; $nota = $_POST["nota"]; $comentario = $_POST["comentario"]; $update= "UPDATE avaliacao SET `nota` = $nota , comentario` = $comentario WHERE íd` = $id"; mysqli_query($con, $update); header('Location: inicio.php'); mysqli_close($con); ?> Can anyone help me?
  7. magcr23

    update

    I have another problem, when i do $updateCat2= "UPDATE categoria SET id = DEFAULT, nome = '$novoCat', caminhoImagem = '$caminho' WHERE nome = '$selectCat' "; all the updates categorys will get id=0. how can i make it continue the auto increment? I mean, if i had id = 1,2,3,4,5 and i update the id=3 it will keep id=3
  8. magcr23

    update

    thx for the help, i made it echo "<option value='", $row{"nome"}, "'>", $row{"nome"}, "</option>";
  9. magcr23

    update

    yeah i found that, but keeps the same error: UPDATE categoria SET id = DEFAULT, nome = 'tas', caminhoImagem = 'bianca5.PNG' WHERE nome = ''
  10. magcr23

    update

    Hi again, i uses an echo $updateCat; and that's what i got: O upload do ficheiro bianca5.PNG deu certo. UPDATE categoria SET id = DEFAULT, nome = 'tas', caminhoImagem = 'bianca5.PNG' WHERE nome = '' I know where the error is, but not how fix it...
  11. magcr23

    update

    Hi, i'm having a problem with update data: I have a page to create a category (category = categoria ,in my code) and it's working, but now i need another page to update the category if it's need, and that's where the error begings... First i create this form: <form action='altcategoria.php' method='POST' enctype='multipart/form-data'> <select name="updateCategoria"> <?php $consulta = "SELECT nome FROM categoria ORDER BY id"; $resultado = mysqli_query($con, $consulta); while ($row = mysqli_fetch_array($resultado)){ echo "<option value=''>", $row{"nome"}, "</option>"; } ?> </select> <?php echo"<br />"; ?> <input type="text" name="novoCat" placeholder="Novo nome"> <input type='file' name='myfile2' id='myfile2'> <input type="submit" name="alterarCat" value="Alterar"> </form> And then i created the page altcategoria.php with this code: <?php $con=mysqli_connect("localhost","root","6794","website"); if (mysqli_connect_errno()){ echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $novoCat = $_POST["novoCat"]; $selectCat = $S_POST["updateCategoria"]; //INSERIR IMAGEM $name = $_FILES["myfile2"]["name"]; $type = $_FILES["myfile2"]["type"]; $size = $_FILES["myfile2"]["size"]; $temp = $_FILES["myfile2"]["tmp_name"]; $error = $_FILES["myfile2"]["error"]; $i = 1; $actual_name = pathinfo($name,PATHINFO_FILENAME); $original_name = $actual_name; $extension = pathinfo($name, PATHINFO_EXTENSION); $nome = $actual_name.".".$extension; $caminho = $name; if($error > 0){ die("Erro"); } else{ if($type == "image/jpg" || $type == "image/png" || $type == "image/jpeg"){ if(file_exists('imgcategoria/' . isset($_FILES[$name]['name']))){ while(file_exists('imgcategoria/'.$actual_name.".".$extension)){ $actual_name = (string)$original_name.$i; $nome = $actual_name.".".$extension; $i++; } echo "O upload do ficheiro " . $nome . " deu certo."; //mover ficheiro para pasta imgcategoria move_uploaded_file($temp,"imgcategoria/".$nome); //inserir caminho do ficheiro na base dados $caminho2 = $nome; $update2 = "INSERT INTO imagem(id, caminho) VALUES (DEFAULT, '$caminho2')"; mysqli_query($con, $update2); $updateCat= "UPDATE categoria SET id = DEFAULT, nome = '$novoCat', caminhoImagem = '$caminho2' WHERE nome = '$selectCat' "; mysqli_query($con, $updateCat); } else{ //mover ficheiro para pasta imgcategoria move_uploaded_file($temp,"imgcategoria/".$name); //inserir caminho do ficheiro na base dados $caminho = $name; $insereIMG = "INSERT INTO imagem(id, caminho) VALUES (DEFAULT, '$caminho')"; mysqli_query($con, $insereIMG); $updateCat2= "UPDATE categoria SET id = DEFAULT, nome = '$novoCat', caminhoImagem = '$caminho' WHERE nome = '$selectCat' "; mysqli_query($con, $updateCat2); } } else{ die("Tipo/tamanho nao suportado"); } } header('Location: inicio.php'); mysqli_close($con); ?> With that i can upload the file to the table "imagem" but the update of data in the table "categoria" it's not working. Anyone can help me? Btw: i'm sending the code in attachment to a better read. altcategoria.php
  12. yeah i did it, i was using the replace tool of notepad++ and didn't noticed that xD. It's working already but thx anyway
  13. Hi guys, i'm trying to upload a file and while the name already exists it add a number (1 then 2 then 3....). I made it work in one file, but now i switched the folder and i can't make it work. There's the code: <?php $con=mysqli_connect("localhost","root","6794","website"); if (mysqli_connect_errno()){ echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $categoria = $_POST["categoria"]; //INSERIR IMAGEM $name = $_FILES["myfile"]["name"]; $type = $_FILES["myfile"]["type"]; $size = $_FILES["myfile"]["size"]; $temp = $_FILES["myfile"]["tmp_name"]; $error = $_FILES["myfile"]["error"]; $i = 1; $actual_name = pathinfo($name,PATHINFO_FILENAME); $original_name = $actual_name; $extension = pathinfo($name, PATHINFO_EXTENSION); $nome = $actual_name.".".$extension; $caminho = $name; if($error > 0){ die("Erro"); } else{ if($type == "imgcategoria/jpg" || $type == "imgcategoria/png" || $type == "image/jpeg"){ if(file_exists('image/' . isset($_FILES[$name]['name']))){ while(file_exists('imgcategoria/'.$actual_name.".".$extension)){ $actual_name = (string)$original_name.$i; $nome = $actual_name.".".$extension; $i++; } echo "O upload do ficheiro " . $nome . " deu certo."; //mover ficheiro para pasta imgcategoria move_uploaded_file($temp,"imgcategoria/".$nome); //inserir caminho do ficheiro na base dados $caminho2 = $nome; $insere2 = "INSERT INTO imagem(id, caminho) VALUES (DEFAULT, '$caminho2')"; mysqli_query($con, $insere2); $imgCat = "INSERT INTO categoria (id, nome, caminhoImagem) VALUES ( DEFAULT, '$categoria', '$caminho')"; mysqli_query($con, $imgCat); } else{ //mover ficheiro para pasta imgcategoria move_uploaded_file($temp,"imgcategoria/".$name); //inserir caminho do ficheiro na base dados $caminho = $name; $insereIMG = "INSERT INTO imagem(id, caminho) VALUES (DEFAULT, '$caminho')"; mysqli_query($con, $insereIMG); $imgCat2 = "INSERT INTO categoria (id, nome, caminhoImagem) VALUES ( DEFAULT, '$categoria', '$caminho')"; mysqli_query($con, $imgCat2); } } else{ die("Tipo/tamanho nao suportado"); } } header('Location: inicio.php'); mysqli_close($con); ?> The problem that i find is that when i have: if($type == "imgcategoria/jpg" || $type == "imgcategoria/png" || $type == "image/jpeg"){ if(file_exists('image/' . isset($_FILES[$name]['name']))){ the upload works but it don't change the name. if i use: if($type == "imgcategoria/jpg" || $type == "imgcategoria/png" || $type == "imgcategoria/jpeg"){ if(file_exists('imgcategoria/' . isset($_FILES[$name]['name']))){ i get the error in die("Tipo/tamanho nao suportado"); and the upload don't work. Anyone know how to solve that?
  14. Hi, i need to create a page where it show's all the new registrations. I thought in create a page where it show's all registrations. But that's not working so well... <?php @$today = getdate(); print_r($today); ?> <?php $con=mysqli_connect("localhost","root","6794","website"); if (mysqli_connect_errno()){ echo "Failed to connect to MySQL: " . mysqli_connect_error(); } ?> <div class="row"> <form action="novos.php" method="post" > <?php $mostra= "SELECT COUNT(*) FROM `artesoes` WHERE data = $today"; $query = mysqli_query($con, $mostra); while($ln = mysqli_fetch_assoc($query)){ echo @$ln[nome]; echo '<a href="ativar.php?teste='.$ln['id'].'"></a>'; echo '<br /><hr />'; } ?> </form> </div> ?php mysqli_close($con); ?> Someone can tell me what am i doing wrong? Or if there's a better way to do it?
  15. yeah 1 of them had, thx for the help it's fixed
  16. Hi guys, I have a page with this code: <?php require "verificauser.php"; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content=""> <meta name="author" content=""> <title>SB Admin - Bootstrap Admin Template</title> <link href="css/bootstrap.min.css" rel="stylesheet"> <link href="css/sb-admin.css" rel="stylesheet"> <link href="css/plugins/morris.css" rel="stylesheet"> <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"> </head> <body> <div id="wrapper"> <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation"> <?php $con=mysqli_connect("localhost","root","6794","website"); // Check connection if (mysqli_connect_errno()){ echo "Failed to connect to MySQL: " . mysqli_connect_error(); } ?> <?php include("menuLateral.php"); include("menuTop.php"); ?> </nav> <div id="page-wrapper"> <div class="container-fluid"> <div class="row"> <div class="col-lg-12"> <div class="alert alert-info alert-dismissable"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> Lista de Artesões </div> </div> </div> <div class="row"> <?php $mostra= "SELECT * FROM artesoes"; mysqli_query($con, $mostra); ?> </div> <?php mysqli_close($con); ?> </body> </html> and it gives me an error: Warning: mysqli_query(): Couldn't fetch mysqli in C:\Users\TheMagcr23\Documents\usb\root\admin\artesoes.php on line 66 how can i fix that? someone can help me?
  17. yeah i know that, all i asked was if someone knew where i could get. About the simple, what i mean is that i wanted one were i don't need to change many things. Anyway i already did it. I decided create one by my one. i wanted to download one to save time but since it was taking to long... about the http://www.webestool.../pm/list_pm.php , i was doing a select in the wrong place...
  18. I need to do something like that http://www.webestools.com/ftp/ybouane/scripts_tutorials/php/pm/list_pm.php I think this one is very good (don't like the layout xd) but i can't make it work on mine database.
  19. Someone know where can i get a free and simple private message system? i found a few but they were to complex and i couldn't make it work with my database.
  20. I think that half of the problem is solved, with that i can see the right user who's logged. $row=mysqli_fetch_array($resultado,MYSQLI_ASSOC); $user2 = $_SESSION["user"]; echo $user2; But how can i update an password? I tryed with that: $updatePW= "UPDATE admin SET password = sha1('$new') WHERE user = password = sha1('$old') "; But it update all the equal passwords. So i tryed with that: $updatePW= "UPDATE admin SET password = sha1('$new') WHERE user = $user2 && password = sha1('$old') "; But it don't work... What can i do?
  21. I tried to do something like that: $row=mysqli_fetch_array($resultado,MYSQLI_ASSOC); $user = $row['user']; echo $user; But the result is the same. Can you tell me what am i doing wrong? Or modify my code to do what i need? I need this problem solved to continue with my project, or i'll fail in my class xD
  22. Hi guys, i have this code: $sql="SELECT * FROM admin"; $resultado = mysqli_query($con, $sql); $row=mysqli_fetch_array($resultado,MYSQLI_NUM); <?php echo $row[0] ?> It returns the first user of the table, but i want the user who's loged, someone can help me with that?
  23. cyberRobot forget that xD I made it by url, i think it would be easier
  24. Something like that? $id=$row{"id"};
×
×
  • 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.