缺少论点

时间:2017-06-02 13:02:45

标签: php mysql pdo

所以我正在开展一个学校项目,在那里我们需要建立一个租用电影的网站,而且我有点卡住了。

我得到错误:

  

致命错误:带有消息'SQLSTATE [42000]的未捕获异常'PDOException':语法错误或访问冲突:1064 SQL语法中有错误;在第334行的/home/ubuntu/workspace/classes/video.php第1行'检查与您的MySQL服务器版本对应的手册,以获得正确的语法使用'WHERE idFilm = NULL)

     

(!)PDOException:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;在第334行的/home/ubuntu/workspace/classes/video.php第1行查看与您的MySQL服务器版本对应的手册,以获得正确使用的语法'WHERE idFilm = NULL)

这个想法是你可以创建一个新电影并添加一个或多个类型。我没有把流派连接到电影上。

所以我的代码是:

<?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>';
        }
    }

1 个答案:

答案 0 :(得分:2)

您在此处缺少列目的地。我不熟悉Pdo方法,但我认为where子句也不在values语句中。

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

你应该这样做:

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