失踪的论点

失踪的论点

问题描述:

所以我正在一个学校项目上工作,我们需要建立一个网站租赁电影,我还挺卡住。失踪的论点

即时得到错误:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 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 'WHERE idFilm = NULL)' at line 1' in /home/ubuntu/workspace/classes/video.php on line 334

(!) PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 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 'WHERE idFilm = NULL)' at line 1 in /home/ubuntu/workspace/classes/video.php on line 334

的想法是,你可以创建一个新的电影和添加一个或多个流派。我无法将流派连接到电影。

所以我的代码是:

<?php 
    include('security.php'); 
     $genre = $video->getAllGenre(); 
    if(isset($_POST['submit'])){ 
     $error = ""; 
     //var_dump($_POST); 
     $target_dir = $_SERVER['DOCUMENT_ROOT'].'/images/covers/'; 
     $temp = explode(".", $_FILES["file"]["name"]); 
     $fileName = $video->generateCoverName() .'.'. end($temp); 
     $target_file = $target_dir . $fileName; 
     //echo('Target file: '.$target_file); 
     $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); 
     $check = getimagesize($_FILES["file"]["tmp_name"]); 
     if($check == false) { 
      $error = "Bestand is geen foto."; 
     } 
     if ($_FILES["file"]["size"] > 50000000) { 
      $error = "Sorry, bestand is te groot."; 
     } 
     if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" 
      && $imageFileType != "gif") { 
      $error = "Sorry, alleen jpg, png, jpeg en gif zijn toegestaan."; 
     } 
     if (!$error) { 
      if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) { 
       //echo "The file ". $fileName. " has been uploaded."; 
       $video->genreToFilm($_POST['idFilm'], $_POST['idGenre']); 
       $video->newVideo($_POST['titel'], $_POST['aantal'], $fileName, $_POST['omschrijving'], $_POST['prijs']); 
      } else { 
       echo("Sorry, er was een probleem met het uploaden van uw bestand."); 
      } 
     } else { 
      print('<div class="alert alert-info fade-out">'.$error.'</div>'); 
     } 

    } 
?> 
<div class="row"> 
    <div class="col-xs-12 col-sm-12 col-md-12 loginborder"> 
     <form role="form" method="post" action="" autocomplete="off" enctype="multipart/form-data"> 
      <h2 class="loginhead">Film toevoegen</h2> 
      <hr> 
       <div class="registrationform"> 
       <div class='row'> 
        <div class="form-group col-xs-12 col-sm-12 col-md-6"> 
         <p>Titel:</p> 
         <input type="text" name="titel" id="titel" class="form-control input-lg" required value="<?php if(isset($error)){ print($_POST['titel']); } ?>" tabindex="1"> 
        </div> 
        <div class="form-group col-12 col-xs-12 col-sm-12 col-md-6"> 
         <p>Upload een coverfoto:</p> 
         <input type="file" name="file" id="file" required> 
        </div> 
       </div> 
       <div class='row'> 
        <div class="omschrijving form-group col-xs-12 col-sm-12 col-md-6"> 
         <p>Omschrijving:</p> 
         <textarea style="resize: none;" name="omschrijving" rows="12" cols="50" placeholder="Omschrijving van de film..." required class="form-control"><?php if(isset($error)){ print($_POST['omschrijving']); }?></textarea> 
        </div> 
        <div class="form-group col-xs-12 col-sm-12 col-md-3"> 
         <p>Aantal:</p> 
         <input type="number" name="aantal" id="aantal" class="form-control input-lg" min="0" max="1000" step="1" required value="<?php if(isset($error)){ print($_POST['aantal']); } ?>" tabindex="1"> 
        </div> 
        <div class="form-group col-xs-12 col-sm-12 col-md-3"> 
         <p>Prijs:</p> 
         <input type="number" name="prijs" id="prijs" class="form-control input-lg" min="0" max="9999.99" step="0.01" required value="<?php if(isset($error)){ print($_POST['aantal']); } ?>" tabindex="1"> 
        </div> 
        <div class="form-group col-xs-12 col-sm-12 col-md-2"> 
         <p>Genre 1:</p> 
         <select name="genre1" class="form-control input-lg"> 
          <?php foreach ($genre as $gen) { 
           print(
             '<option value='.$gen['idGenre'].'>'.$gen['genre'].'</option>'); 
          } ?> 
         </select> 
        </div> 
        <div class="form-group col-xs-12 col-sm-12 col-md-2"> 
         <p>Genre 2:</p> 
         <select name="genre2" class="form-control input-lg"> 
          <?php foreach ($genre as $gen) { 
           print('<option value='.$gen['idGenre'].'>'.$gen['genre'].'</option>'); 
          } ?> 
         </select> 
        </div> 
        <div class="form-group col-xs-12 col-sm-12 col-md-2"> 
         <p>Genre 3:</p> 
         <select name="genre3" class="form-control input-lg"> 
          <?php foreach ($genre as $gen) { 
           print('<option value='.$gen['idGenre'].'>'.$gen['genre'].'</option>'); 
          } ?> 
         </select> 
        </div> 
       </div> 
       <div class="row"> 
        <div class="form-group col-xs-12 col-sm-12 col-md-2"> 
         <p>Acteur 1:</p> 
         <input type="text" name="acteurs" id="acteur1" class="form-control input-lg" min="0" max="1000" step="1" value="<?php if(isset($error)){ print($_POST['acteurs']); } ?>" tabindex="1"> 
        </div> 
        <div class="form-group col-xs-12 col-sm-12 col-md-2"> 
         <p>Acteur 2:</p> 
         <input type="text" name="acteur2" id="acteur2" class="form-control input-lg" min="0" max="1000" step="1" value="<?php if(isset($error)){ print($_POST['acteurs']); } ?>" tabindex="1"> 
        </div> 
        <div class="form-group col-xs-12 col-sm-12 col-md-2"> 
         <p>Acteur 3:</p> 
         <input type="text" name="acteur3" id="acteur3" class="form-control input-lg" min="0" max="1000" step="1" value="<?php if(isset($error)){ print($_POST['acteurs']); } ?>" tabindex="1"> 
        </div> 
        <div class="form-group col-xs-12 col-sm-12 col-md-2"> 
         <p>Acteur 4:</p> 
         <input type="text" name="acteur4" id="acteur4" class="form-control input-lg" min="0" max="1000" step="1" value="<?php if(isset($error)){ print($_POST['acteurs']); } ?>" tabindex="1"> 
        </div> 
        <div class="form-group col-xs-12 col-sm-12 col-md-2"> 
         <p>Acteur 5:</p> 
         <input type="text" name="acteur5" id="acteur5" class="form-control input-lg" min="0" max="1000" step="1" value="<?php if(isset($error)){ print($_POST['acteurs']); } ?>" tabindex="1"> 
        </div> 
        <div class="submitVideoToevoegen col-xs-12 col-md-2"> 
         <input type="submit" name="submit" value="Verstuur" class="btn btn-lg " tabindex="5"> 
        </div> 
       </div> 
      </div> 
     </form> 
    </div> 
</div> 

和类的代码是:

public function genreToFilm($idFilm, $idGenre){ 
     try{ 
      $stmt = $this->_db->prepare('INSERT INTO FilmGenre 
             VALUES(:idFilm, :idGenre WHERE idFilm = :idFilm)'); 
      if($stmt->execute(array(':idGenre' => $idGenre, 
            ':idFilm' => $idFilm))){ 
       return true; 
      } else { 
       return false; 
      } 

     } catch (PDOExeption $e) { 
      echo '<p class="bg-danger">'.$e->getMessage().'</p>'; 
     } 
    } 
+0

你idFilm值为空,因此没有设置 –

+1

没有'INSERT INTO..WHERE'。你的意思是运行一个'UPDATE'查询吗?还有围绕这个的括号是错误的。 – Qirel

+0

你想创建一个新的行,或者修改一个现有的行 – RiggsFolly

,你在这儿缺列的目标。我不擅长Pdo方法,但我不认为where语句也可以在价值声明中。

$this->_db->prepare('INSERT INTO FilmGenre VALUES(:idFilm, :idGenre WHERE idFilm = : 

你应该这样做:

$this->_db->prepare('INSERT INTO FilmGenre (idFilmColumn, idGenreColumn) VALUES(:idFilm, :idGenreColumn)') ; 
+0

OP不想插入语句。可能是更新声明会做。 – Akintunde007

+0

即使它应该是一个INSERT查询,您并不总是需要指定列 - 如果您查看手册,请https://dev.mysql.com/doc/refman/5.7/en /insert.html – Qirel

+0

@Qirel在我看来,他正在尝试创建一个简单的链接表行。所以也许它应该是一个插入 – RiggsFolly