Error Mysql syntax

Asked

Viewed 81 times

1

Good morning, I have an error in my upload system. The error is the following:

You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use near '','845941', 'adventure', 'video/mp4', '28813678')' at line 2

I could not solve so far, if anyone can help me, I thank. I will leave the code of the form upload and the PHP file.

This is my form of upload:

          <form role="form" method="post" action="inclusao.php" enctype="multipart/form-data">
          <div class="row">


              <div class="box box-success">
                <div class="box-header">
                  <h3 class="box-title">Filmes</h3>
                </div>
                <div class="box-body">

                  <!-- nome -->
                  <div class="form-group">
                    <label>Nome:</label>
                    <div class="input-group">
                      <div class="input-group-addon">
                        <i class="fa fa-tags"></i>
                      </div>
                      <input type="text" class="form-control" name="nome" placeholder="Nome Do filme"/>
                    </div><!-- /.input group -->
                  </div><!-- /.form group -->
                  <!-- nome -->

                  <!-- Date dd/mm/yyyy -->
                  <div class="form-group">
                    <label>Data:</label>
                    <div class="input-group">
                      <div class="input-group-addon">
                        <i class="fa fa-calendar"></i>
                      </div>
                      <input type="text" name="data" class="form-control"/>
                    </div><!-- /.input group -->
                  </div><!-- /.form group -->


                  <div class="form-group">
                    <label>Categorias:</label>
                    <div class="input-group">
                      <div class="input-group-addon">
                        <i class="fa fa-info"></i>
                      </div>
                     <select name="categoria" class="form-control">
                       <option></option>
                       <option value="acao">Ação</option>
                       <option value="animacao">Animação</option>
                       <option value="aventura">Aventura</option>
                       <option value="comedia">Comédia</option>
                       <option value="cromantica">Comédia Romântica</option>
                       <option value="corrida">Corrida</option>
                       <option value="classico">Clássicos</option>
                       <option value="documentario">Documentários</option>
                       <option value="drama">Drama</option>
                       <option value="faroeste">Faroeste</option>
                       <option value="ficcao">Ficção Científica</option>
                       <option value="guerra">Guerra</option>
                       <option value="herois">Herois</option>
                       <option value="infantil">Infantil</option>
                       <option value="luta">Lutas</option>
                       <option value="romance">Romance</option>
                       <option value="nacional">Nacional</option>
                       <option value="policial">Policial</option>
                       <option value="suspense">Suspense</option>
                       <option value="terror">Terror</option>
                     </select>
                    </div><!-- /.input group -->
                  </div><!-- /.form group -->
                  <div class="form-group">
                  <div class="input-group">
                      <div class="input-group-addon">
                        <i class="fa fa-info"></i>
                      </div>
                     <select name="categoria2" class="form-control">
                       <option></option>
                       <option value="acao">Ação</option>
                       <option value="animacao">Animação</option>
                       <option value="aventura">Aventura</option>
                       <option value="comedia">Comédia</option>
                       <option value="cromantica">Comédia Romântica</option>
                       <option value="corrida">Corrida</option>
                       <option value="classico">Clássicos</option>
                       <option value="documentario">Documentários</option>
                       <option value="drama">Drama</option>
                       <option value="faroeste">Faroeste</option>
                       <option value="ficcao">Ficção Científica</option>
                       <option value="guerra">Guerra</option>
                       <option value="herois">Herois</option>
                       <option value="infantil">Infantil</option>
                       <option value="luta">Lutas</option>
                       <option value="romance">Romance</option>
                       <option value="nacional">Nacional</option>
                       <option value="policial">Policial</option>
                       <option value="suspense">Suspense</option>
                       <option value="terror">Terror</option>
                     </select>
                    </div>
                    </div>
                  <!-- IP mask -->
                  <div class="form-group">
                    <label>Lancamento:</label>
                    <div class="input-group">
                      <div class="input-group-addon">
                        <i class="fa fa-laptop"></i>
                      </div>
                     <select name="lancar" class="form-control">
                       <option>Se O Filme For Um Lançamento Escolher A Opção Abaixo:</option>
                       <option value="lancamento">Lançamento</option>
                     </select>
                    </div><!-- /.input group -->
                  </div><!-- /.form group -->

                  <div class="form-group">
                    <label>Sinopse:</label>
                    <div class="input-group">
                      <div class="input-group-addon">
                        <i class="fa fa-edit"></i>
                      </div>
                      <textarea class="form-control" rows="3" name="sinopse" placeholder="Escreva a Sinopse do Filme"></textarea>
                    </div><!-- /.input group -->
                  </div><!-- /.form group -->
                <div class="form-group">
                    <label>Hora:</label>
                    <div class="input-group">
                      <div class="input-group-addon">
                        <i class="fa fa-clock-o"></i>
                      </div>
                      <input type="text" class="form-control" name="hora" placeholder="Hora do Filme Ex: 1hr40">
                    </div><!-- /.input group -->
                  </div><!-- /.form group -->
                <div class="form-group">
                    <label>Imagem:</label>
                    <div class="input-group">

                     <input type="file" name="img[]" multiple>
                    </div><!-- /.input group -->
                  </div><!-- /.form group -->
              <div class="form-group">
                    <label>Filme:</label>
                    <div class="input-group">

                      <input type="file" name="file[]" multiple>
                    </div><!-- /.input group -->
                  </div><!-- /.form group -->
                  <div class="box-footer">
                    <button type="submit" class="btn btn-primary" name="submit">Cadastrar</button>
                  </div>

                </div><!-- /.box-body -->
              </div><!-- /.box -->

</form>

And this is the action from it, the page in PHP:

<?php

require"conexao.php";

if(isset($_POST['submit'])){    
//dados que serão incluidos
$nome=$_POST['nome'];
$data=$_POST['data'];
$categoria=$_POST['categoria'];
$categoria2=$_POST['categoria2'];
$lancar=$_POST['lancar'];
$sinopse=$_POST['sinopse'];
$hora = $_POST['hora'];

foreach($_FILES['img']['tmp_name'] as $key => $name_temp){
        $name = $_FILES['img']['name'] [$key];
        $tmpnm = $_FILES['img']['tmp_name'][$key];
        $type = $_FILES['img']['type'][$key];
        $size = $_FILES['img']['size'][$key];

        $dir = "images/capa/".$name;
        $mover = move_uploaded_file($tmpnm , $dir);

        foreach($_FILES['file']['tmp_name'] as $k => $n){
                $nomev = $_FILES['file']['name'] [$k];
                $t = $_FILES['file'] ['tmp_name'] [$k];
                $tipo = $_FILES['file']['type'][$k];
                $tam = $_FILES['file']['size'][$k];


        $dire = "video/".$nomev;
        $move = move_uploaded_file($t , $dire);

        if($mover&&$move){
            $sql = mysql_query("insert into filme(nome, categoria, img, lancamento, sinopse, hora, video, data, type, size, subcategoria, tipo, tam) values('$nome','$categoria','$name','$lancar','$sinopse','$hora'
                ,'$nomev','$data',$type','$size', '$categoria2', '$tipo', '$tam')") or die (mysql_error());
            if($sql){
                echo "Deu Certo";
            }
            else{
                echo "erro database";
            }
        }else{
            echo"nao nao";
        }
        }
    }
}

?>

1 answer

1


Change this line:

 $sql = mysql_query("insert into filme(nome, categoria, img, lancamento, sinopse, hora, video, data, type, size, subcategoria, tipo, tam) values('$nome','$categoria','$name','$lancar','$sinopse','$hora'
                ,'$nomev','$data',$type','$size', '$categoria2', '$tipo', '$tam')") or die (mysql_error());

For this:

 $sql = mysql_query("insert into filme(nome, categoria, img, lancamento, sinopse, hora, video, data, type, size, subcategoria, tipo, tam) values('$nome','$categoria','$name','$lancar','$sinopse','$hora','$nomev','$data','$type','$size', '$categoria2', '$tipo', '$tam')") or die (mysql_error());

In this case a ' to close $type. Hence the error. If persists, do so as follows:

$sql = mysql_query("
                        INSERT INTO
                            filme
                        (
                            nome, 
                            categoria, 
                            img, 
                            lancamento, 
                            sinopse, 
                            hora, 
                            video, 
                            data, 
                            type, 
                            size, 
                            subcategoria, 
                            tipo, 
                            tam
                        )
                            VALUES
                        (
                            $nome,
                            $categoria,
                            $name,
                            $lancar,
                            $sinopse,
                            $hora,
                            $nomev,
                            $data,
                            $type,
                            $size,
                            $categoria2,
                            $tipo, 
                            $tam
                        )

");
  • Could you tell me what you changed in the code? I couldn’t see the difference the only thing I noticed was that Voce did everything in a row that has relationship?

  • No longer solved the error Thank you very much Thank you guys Brand here

  • One of the variables was missing, so it didn’t work. '$data',$type' - note that there is a missing ', in $type, so it was an error.

  • I’ve sometimes noticed this tiny detail of error

  • Exactly @carlosgoncalves. If you want me Add to skype: srandrebaill, I’m always online when you need me. Hug.

  • 1

    thanks so i open skype if i remember add yes

Show 1 more comment

Browser other questions tagged

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