When registering the php form with an image it only sends the image to the folder but does not register the data in the database

Asked

Viewed 41 times

0

This is my form

<form method="post" id="show" action="inserir/inserir_show.php" enctype="multipart/form-data">
                    <h4>Nome do show</h4>
                    <div class="form-group">
                        <input type="text" class="form-control" name="nome" id="inputEmail" required="">
                    </div>
                    <h4>Diretor do show</h4>
                    <div class="form-group">
                        <input type="text" class="form-control" name="diretor" id="inputEmail" required="">
                    </div>
                    <h4>Foto do show</h4>
                    <div class="form-group">
                        <input type="file" class="form-control" name="image" id="inputEmail" required="">
                    </div>
                    <h4>Frase</h4><!--frase-->
                    <div class="form-group">
                        <input type="text" class="form-control" name="frase" id="inputEmail" required="">
                    </div>
                    <h4>Descrição</h4><!--descrição-->
                    <div class="form-group">
                        <input type="text" class="form-control" name="descricao" id="inputEmail" required="">
                    </div>
                    <h4>Data do show</h4>
                    <div class="form-group">
                        <input type="date" class="form-control" name="data" id="inputEmail" required="">



                    </div>
                    <h4>Local do show</h4>
                    <div class="form-group">
                        <input type="text" class="form-control" name="local" id="inputEmail" required="">
                    </div>
                    <h4>Categoria do show</h4>
                    <div class="form-group">
                        <input type="text" class="form-control" name="categoria" id="inputEmail" required="">
                    </div>

                    <button type="submit" class="btn btn-primary">Enviar</button>

                </form>

And insert it into the bank

<?php

include "conecta.php";

$nome = $_POST['nome'];
$diretor = $_POST['diretor'];
$data = $_POST['data'];
$descricao = $_POST['descricao'];
$frase = $_POST['frase'];
$local = $_POST['local'];
$categoria = $_POST['categoria'];
$foto = $_FILES['image']['name'];
$target = "img/" .basename($_FILES['image']['name']);



    $cadastro_show = "INSERT INTO show(nomeShow, diretorShow, dataShow, descricaoShow, fraseShow, localShow, categoriaShow, fotoShow) VALUES ('$nome', '$diretor', '$data', '$descricao', '$frase', $local', '$categoria', '$foto')";

    mysqli_set_charset($link, x'utf8');

    mysqli_query($link, $cadastro_show);

    if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
     echo"<script language='javascript' type='text/javascript'>alert('Cadastrado com sucesso :)');window.location.href='../shows.php';</script>";
}else{
     echo"<script language='javascript' type='text/javascript'>alert('Houve um Erro ao cadastrar o show');window.location.href='../shows.php';</script>";
}


mysqli_close($link);

?>

The image I select in the form sends to the folder "img/" and appears the message you registered but does not send any data to the bank, someone can help me?

  • Victory to be able to answer with more certainty, would need time as this being made the database connection. Passes the code of connects.php Apparently everything is in order in the code posted, and I would include a transaction control, just to make sure that the upload and the data Insert would happen.

  • this is the connect.php <? php $server='localhost'; $user ='root'; $password =''; $bank ='bancoppi'; $link = mysqli_connect($server,$user,$password,$bank) or die; ;?>

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.