Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Php向mySQL提交评论_Php - Fatal编程技术网

使用Php向mySQL提交评论

使用Php向mySQL提交评论,php,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']);

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, ));

?>
//版主请出示图片,因为我仍然没有权利

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

无冒号

将PDO放入try-catch块并回显错误可能会对您有所帮助
试试{/*你的代码*/}catch(PDOException$pe){echo$pe;}
为什么你需要用文本制作一个图像?你能帮我修复我的代码吗?用“?”标记替换你的:命名变量,并将你的数组从assoc改为常规数组(数组($var1,$var2,$var3))。再次,请展示代码示例,我是php的新手:)
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
$sth4->execute(array( 'comm' => $comm, 'pID4' => $pID4, 'cID' => $cID, ));