0
I am beginner, do not know how to show pictures saved by name in the database
// function
function cadastraUsuario($conn, $nome_topper, $email_topper, $senha_topper,
$data_nasc_topper, $sexo_topper) {
$query = "INSERT INTO participantes (nome_topper, email_topper,
senha_topper, data_nasc_topper, sexo_topper) " . "VALUES ('{$nome_topper}',
'{$email_topper}', '{$senha_topper}', '{$data_nasc_topper}',
'{$sexo_topper}')"; return mysqli_query($conn, $query); } –
// CODIGO DE CADASTRO, FUNCIONANDO
$nome_topper = "$_POST[nome] $_POST[sobrenome]";
$email_topper = $_POST['email'];
$senha_topper_1 = $_POST['senha1'];
$senha_topper_2 = $_POST['senha2'];
$data_nasc_topper = $_POST['dataNasc'];
$sexo_topper = $_POST['sexo'];
if (isset($_FILES['imagem'])) {
$extensao = strtolower(substr($_FILES['imagem']['name'], -4));
$novo_nome = md5(time()) . $extensao;
$diretorio = "upload/";
move_uploaded_file($_FILES['imagem']['tmp_name'], $diretorio.$novo_nome);
$query2 = "insert into participantes (arquivo, data_upload) values ('$novo_nome', now())";
mysqli_query($conn, $query2);
if ($senha_topper_1 == $senha_topper_2) {
if (idade($data_nasc_topper) >= 18) {
if (cadastraUsuario($conn, $nome_topper, $email_topper, $senha_topper_1, $data_nasc_topper, $sexo_topper)) {
session_start();
$_SESSION['logado'] = true;
$_SESSION['nome_logado'] = $nome_topper;
$_SESSION['foto_logado'] = "";
$_SESSION["success"] = "Usuário cadastrado com sucesso.";
header("location: index.php");
} else {
$msg = mysqli_error($conn);
$_SESSION["danger"] = "Usuário não cadastrado: $msg";
$msg = mysqli_error($conn);
header("location:index.php");
}
} else {
$_SESSION["danger"] = "Usuário menor de 18 anos.";
header("location: formCadastrar.php");
}
} else {
$_SESSION["danger"] = "As senhas são diferentes.";
header("location: formCadastrar.php");
} else {
$_SESSION["danger"] = "A imagem esta errada tente novamente";
header("location: formCadastrar.php");
}
There is a flaw in your registration system and you will have to resolve it before proceeding with displaying the images. When the user registers on your system, he uploads the image, but you are not recording the
IDuser in the tableparticipantes. Without this, you will not be able to tell which image belongs to a particular user at the time of displaying it.– user98628
how can I solve this problem ?
– William Gravina
From what I understand, you enter the user through the function:
cadastraUsuario(), right? The problem is that you do the insertion of the image before inserting the user, then it still will not have aIDin your users table. You would have to enter the user before, take the mysqli_insert_id() and then generate theINSERTof the image passing thisID. You can fix me if I’m wrong, I’m saying this based on the snippet of your code that was posted.– user98628
Add this function by editing your post, please.
– user98628