-1
This my script is to insert the name of the image in the bank, is working normally
INSERT.PHP
if ($_POST){
$imagem = $_FILES['img_post'];
$nomeImg = $imagem['name'];
$tmpImg = $imagem['tmp_name'];
$formatoBase = explode('.',$nomeImg);
$formato = end($formatoBase); //jesus
$nomeImg = "paranoid_img_".uniqid().".".$formato;
$titulo = $_POST['titulo_post'];
$descricao = $_POST['descricao_post'];
$texto = $_POST['texto_post'];
$autor = $_SESSION['nome']." ".$_SESSION['sobrenome'];
$url = uniqid();
$pastaImg = "../img/posts";
$query = mysqli_query($conexao, "insert into tbl_post (titulo_post, descricao_post, img_post, texto_post, autor_post, idautor_post, data_post, url_post)
values ('$titulo','$descricao','$nomeImg','$texto','$autor','$id_user','$data','$url')");
if ($query){
$uploadPasta = move_uploaded_file($tmpImg, $pastaImg."/".$nomeImg);
echo "<script>alert('Post enviado!');location.href=('../painel_adm.php');</script>";
} else {
echo "<script>alert('Erro!');location.href=('../upload_post.php');</script>";
}
}
Now I cannot perform the name update if I upload another image by the change form.
CHANGE.PHP
$query1 = mysqli_query($conexao,"select * from tbl_post where url_post = '$url'");
$contSql=mysqli_fetch_array($query1);
if ($_POST){
$id = $contSql['id_post'];
$titulo = $_POST['titulo_post'];
$descricao = $_POST['descricao_post'];
$texto = $_POST['texto_post'];
$imagem = $_FILES['img_post'];
$nomeImg = $imagem['name'];
$tmpImg = $imagem['tmp_name'];
$query2 = mysqli_query($conexao,"update tbl_post set titulo_post='$titulo', descricao_post='$descricao', texto_post = '$texto' img_post='$nomeImg' where id_post = $id");
if ($query2){
echo "<script>alert('Post atualizado!');location.href='show_post.php?url=$url';</script>";
} else {
echo "<script>alert('Erro!');</script>";
}
}
?>
Show any errors? Have you checked if all the data is getting into PHP correctly? Tested SQL elsewhere to make sure it’s working? It seems to me that the problem is on this line
$id = $contSql['id_post'];
, id value is correct?– Costamilam
Yes William, if I remove the image update, the information goes up normal, if I do, just pop up the error Alert I put on Else if the $query was not executed correctly
– Douglas Lima