2016-07-25 2 views
-2

Пожалуйста, помогите не решить, попробуйте с трех дней, но не можете понять, в чем причина, по которой он бросает мне такое сообщение. (ниже мой полный код).PDOException: SQLSTATE [HY093]: Неверный номер параметра: параметр не определен

<!DOCTYPE html> 
<html> 
<head> 
    <title>Insert New Post</title> 
</head> 
<body> 
<form method="post" action="insert_post.php" enctype="multipart/form-data"> 
<table align="center" border="10" width="600"> 
    <tr> 
     <td align="center" colspan="5" bgcolor="yellow"><h1>Insert New Post Here</h1></td> 
    </tr> 

    <tr> 
     <td align="right">Post Title:</td> 
     <td><input type="text" name="title" size="40"></td> 
    </tr> 
    <tr> 
     <td align="right">Post Author:</td> 
     <td><input type="text" name="author"></td> 
    </tr> 
    <tr> 
     <td align="right">Post image:</td> 
     <td><input type="file" name="image_name"></td> 
    </tr> 
    <tr> 
     <td align="right">Post Content:</td> 
     <td><textarea name="content" cols="50" rows="20"></textarea></td> 
    </tr> 
    <tr> 

     <td align="center" colspan="5"><input type="submit" name="submit" value="Publish Now"></td> 
    </tr> 

</table>  

</form> 

</body> 
</html> 

Выше форма, чтобы вставить и отправить данные в базе данных

// PHP 

    <?php 
include("includes/connect.php"); 

if (isset($_POST['submit'])) { 

    $title = $_POST['title']; 
    $datenow = date('Y/m/d'); 
    $author = $_POST['author']; 
    $content = $_POST['content']; 
    $image_name = $_FILES['image_name']['name']; 
    $image_type = $_FILES['image_name']['type']; 
    $image_size = $_FILES['image_name']['size']; 
    $image_tmp = $_FILES['image_name']['tmp_name']; 

    if ($title =='' || $author =='' || $content =='') { 
     echo "<script>alert('Any feild is empty')</script>"; 
     exit(); 
    } 
    if ($image_type =='image/jpeg' || $image_type =='image/png' || $image_type =='image/gif') { 

     if ($image_size<=5000000000) { 
      move_uploaded_file($image_tmp, "images/$image_name"); 
     } 
     else{ 
      echo "<script>alert('Image is larger, only 50kb size is allowed')  </script>"; 
     } 
    } 
    else{ 
     echo "<script>alert('image type is invalid')</script>"; 
    } 

    // insert query 
       $sth = $con->prepare(" INSERT INTO posts (post_title, post_date, post_author, post_image, post_content) VALUE (:title,:datenow,:author,:image_name,:content) "); 

    $sth->bindParam(':post_title', $title); 
    $sth->bindParam(':post_date', $datenow); 
    $sth->bindParam(':post_author', $author); 
    $sth->bindParam(':post_image', $image_name); 
    $sth->bindParam(':post_content', $content); 

     $sth->execute(); 

echo "<h1>Form Submited Successfully</h1>"; 

} 

?> 

    // $sth->execute(); is throwing error massage as above 
+0

Вы связывающую ': название,: datenow,: author..' Не': post_title,: post_date..' – Saty

ответ

2

Вы связывание неправильно values.You не свяжите post_ * значение. Смотрите ниже:

$sth = $con->prepare(" INSERT INTO posts (post_title, post_date, post_author, post_image, post_content) VALUES (:post_title,:post_date,:post_author,:post_image,:post_content) "); 

$sth->bindParam(':post_title', $title); 
$sth->bindParam(':post_date', $datenow); 
$sth->bindParam(':post_author', $author); 
$sth->bindParam(':post_image', $image_name); 
$sth->bindParam(':post_content', $content); 
+0

Спасибо msantos ваше большое, за помощь мне ...... – David

+0

Теперь моя треска работает нормально ...! – David

+0

Спасибо. Я рад помочь вам. – msantos

Смежные вопросы