检查textarea不工作的PHP

时间:2018-01-03 07:52:48

标签: php mysql

- 我只想要帖子用户

- 我有两个表(用户,帖子),  我不知道make system post //代码html表单和textarea

               <form method="POST" autocomplete="off" action="">  
            <textarea name="none" class="textarea" placeholder="Quelle est votre question ?"></textarea>

                <select>
                    <option value="filiére" selected="1">Filiére : Accueil</option>
                    <option value="smp">smpc</option>
                    <option value="smp">smia</option>
                    <option value="smp">svt</option>
                    <option value="smp">smp</option>
                    <option value="smp">smc</option>
                    <option value="smp">sma</option>
                    <option value="smp">smi</option>
                    <option value="smp">svi</option>

                </select>

                <select>
                    <option value="accueil" selected="1">Semestre : Accueil</option>
                    <option value="s1">s1</option>
                    <option value="s2">s2</option>
                    <option value="s3">s3</option>
                    <option value="s4">s4</option>
                    <option value="s5">s5</option>
                    <option value="s6">s6</option>                                              
                </select>   

    <button class="btn-ajouter" type="submit" name="ajouter" value="ajouter">ajouter</button>                           
    </form> 
 //code php 
   $userId = $_SESSION['user_id']; 
   if(isset($_POST['ajouter']))
     {
      $post = $_POST['none'];

     $stmt=$connect->prepare('INSERT INTO 
                publications(id_auteur,date_post,post) VALUES(?,NOW(),?) ');
     $stmt->execute(array(

     ':id_auteur' => $userId,
     ':post'      => $post

            ));
         }

代码...致命错误PDO:未捕获PDOException:SQLSTATE [HY093]:参数号无效:参数未定义

1 个答案:

答案 0 :(得分:4)

使用命名占位符

$stmt=$connect->prepare('INSERT INTO 
                publications(id_auteur,date_post,post) VALUES( :id_auteur, NOW(),:post ) ');

    $stmt->execute(array(
        ':id_auteur' => $userId,
        ':post'      => $post
    ));

?作为占位符

$stmt=$connect->prepare('INSERT INTO 
                publications(id_auteur,date_post,post) VALUES( ?, NOW(),? ) ');

    $stmt->execute(array(
        1      => $userId,
        2      => $post
    ));