使用Php将注释提交到mySQL

时间:2011-04-09 21:24:13

标签: php

PHP

<?php
// Insert Comments into Database that user provides
$comm = mysql_real_escape_string($_POST['addComment']);
$pID4 = filter_input(INPUT_GET, 'pID', FILTER_SANITIZE_NUMBER_INT);
$cID = mysql_real_escape_string($_POST['courseInfoDD']);
        $username = "####";
        $password = "####";
        $pdo4 = new PDO('mysql:host=localhost;dbname=####', $username, $password);
        $pdo4->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sth4 = $pdo4->prepare('
    INSERT INTO Comment (info, pID, cID)
    VALUES(:comm, :pID4, :cID);
');
$sth4->execute(array( ':comm' => $comm, ':pID4' => $pID4, ':cID' => $cID, ));

?>

HTML:

<input type='text' id='addComment' name='addComment' tabindex='3' value='Enter comment' />

数据库表: http://postimage.org/image/pfkqxpg/

为什么这不起作用?我是否还需要包括教授? :: http://postimage.org/image/25wsqhap0/

似乎不喜欢这句话:$sth4->execute(array( ':comm' => $comm, ':pIDF' => $pID4, ':cID' => $cID ));你发现错了吗?它抛出错误:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters' in Stack trace: #0  PDOStatement->execute(Array) #1: require_once('/Applications/X...') #2 {main} thrown on line 75

//主持人请显示图片,因为我还没有权利

1 个答案:

答案 0 :(得分:1)

$sth4->execute(array( 'comm' => $comm, 'pID4' => $pID4, 'cID' => $cID, ));

没有冒号