Get image name in mysql for id

0

I would like to know how to get the image name by user id, I have this bd:

I would like to display only the image of the claudiomiro, and not all of those in the bd ... this way:

Ihavethiscodetouploadtheuser/password/name/image,theimageisintheimagesdirectory,andonlythenamegoestobd...

Index.html

<html><head></head><body><formmethod="post" action="index.php">
<label>Usuario:</label><input type="text" name="user">
<label>Senha:</label><input type="password" name="pass"><input type="submit" value="Entrar" />
    </form>
    <form method="post" enctype="multipart/form-data" action="cadastrar.php">
        <table>
  <input type="hidden" name="id"/> 
  <tr><td>Nome:</td><td><input type="text"  name="nome" maxlength="50" /></td></tr>
  <tr><td>Usuário:</td><td><input type="text" name="usuario" maxlength="50" /></td></tr>
  <tr><td>Email:</td><td><input type="text" name="email" maxlength="200" /></td></tr>
  <tr><td>Senha:</td><td><input type="password" name="senha" maxlength="50" /></td></tr>
  <tr><td></td><td><input type="password" name="senha2" maxlength="50"  />
  <tr><td>imagem:</td><td><input type="file" size="60" name="arq" value=""></td></tr>
  <tr><td></td><td><input type="submit" size="60" name="enviar" value="Upload"></td></tr>


 </table>
</form>
</body>
</html>

Index.php:

<?php
require_once("config.php");
mysql_connect("$host", "$usuario", "$senha");
mysql_select_db("$db");
  $user = $_POST['user'];
  $pass = $_POST['pass'];
  $resultado = mysql_query("SELECT * FROM notas WHERE id='".$id."'");
$verificacao = "SELECT * FROM users WHERE usuario ='$user' AND senha = '$pass'";
$resultado = mysql_query($verificacao);
$iniciar = mysql_num_rows($resultado);
mysql_select_db("usuarios", mysql_connect('localhost','root','')); 
$linha = mysql_fetch_array($resultado);
if ($iniciar == 1){

  ?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

  <div id="header"><div id="logo">Logo</div>
    <div id="menu">
    <li><a href="perfil.php?id=<?php echo $linha['nome']; ?>"><?php echo $_POST['user'];?></a></li>
    <li><a href="#">Encontre alguém</a></li>
  </div>
  </div>
</body>
</html>
<?php
}else{
   header("Location: index.html");
}
?>

Register.php

<?php
require_once("config.php");
mysql_connect("$host", "$usuario", "$senha");
mysql_select_db("$db");
if ($_POST['enviar']) {
    $tempname = $_FILES['arq']['tmp_name'];
    $new_name = uniqid();
    $extension = strtolower(pathinfo($_FILES['arq']['name'], PATHINFO_EXTENSION));
    $folder = "imagens";
    $name = $_POST['nome'];
    $usuario = $_POST['usuario'];
    $email = $_POST['email'];
    $senha = $_POST['senha'];
    $senha2 = $_POST['senha2'];
    $verifica = "SELECT *FROM users WHERE usuario = '$usuario'";
    $checar = mysql_num_rows($verifica);
    if ($checar == 0) {
    mysql_query("INSERT INTO users (nome,usuario,email,senha,senha2,foto) VALUES ('".$name."','".$usuario."','".$email."','".$senha."','".$senha2."','".$new_name.".".$extension."')");
    move_uploaded_file($tempname, $folder."/".$new_name.".".$extension);
    echo "Usuario cadastrado com sucesso";
    }else{
        echo "O usuario já existe!";
    }

}
?>

Profile.php

<?php 
require_once('config.php');
require_once("config.php");
mysql_connect("$host", "$usuario", "$senha");
mysql_select_db("$db");
$sql = mysql_query("SELECT * FROM users")OR DIE(mysql_error());

  while ($res = mysql_fetch_array($sql)) {
    $id    = $res[0];      

echo ("<img src=imagens/".$id.$res[foto]);    

}
?>  

(where the image should go) But all the stored images go, but I would like only that of the claudiomiro to appear ... I keep waiting = D

    
asked by anonymous 24.10.2015 / 22:46

1 answer

1

I changed line 24 to id, and I used $ _GET to get the id in profile.php: D

<?php
require_once("config.php");
mysql_connect("$host", "$usuario", "$senha");
mysql_select_db("$db");

  $user = $_POST['user'];
  $pass = $_POST['pass'];
  $resultado = mysql_query("SELECT * FROM notas WHERE id='".$id."'");
$verificacao = "SELECT * FROM users WHERE usuario ='$user' AND senha = '$pass'";
$resultado = mysql_query($verificacao);
$iniciar = mysql_num_rows($resultado);
mysql_select_db("usuarios", mysql_connect('localhost','root','')); 
$linha = mysql_fetch_array($resultado);
if ($iniciar == 1){

  ?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

  <div id="header"><div id="logo">Logo</div>
    <div id="menu">
    <li><a href="perfil.php?id=<?php echo $linha['id']; ?>"><?php echo $_POST['user'];?></a></li>
    <li><a href="#">Encontre alguém</a></li>
  </div>
  </div>
</body>
</html>
<?php
}else{
   header("Location: index.html");
}
?>



<?php 
require_once('config.php');
$id = $_GET['id'];
mysql_connect("$host", "$usuario", "$senha");
mysql_select_db("$db");
$sql = mysql_query("SELECT * FROM users where id = '$id'")OR DIE(mysql_error());

  while ($res = mysql_fetch_array($sql)) {   

?>
<img src="imagens/<?php echo $res['foto']?>" width="260" height="260">
<?php
}
?>  
    
25.10.2015 / 00:23