请帮我在以下内容中插入多个值:$ query-> execute(array());

时间:2016-08-28 20:22:20

标签: sql arrays pdo insert execute

我有一点PDO,我试图插入一个非常简单的SQL数据库。 控制台显示从PHP开始,print_r()完全给出了我希望的响应, 但是 - 字段没有插入到我的SQL dBase中。

拜托,我在做错了什么?:

我有两张照片,如果有帮助的话:

响应: http://extoleducation.ipage.com/extol/test/functioning/test/pic1.png

的dBase: http://extoleducation.ipage.com/extol/test/functioning/test/pic2.png



<?php
$pdo = new PDO("mysql:host=extoleducation.ipagemysql.com;dbname=trialdb","username","password");

if(isset($_POST['sample1'])) {
    $sql = "INSERT INTO `sampletable` (`sampleline1`, 'sampleline2', 'sampleline3', 'sampleline4') VALUES (:sample1, :sample2, :sample3, :sample4)";
    $query = $pdo->prepare($sql);
    $query->execute(array(':sample1'=>$_POST['sample1'],':sample2'=>$_POST['sample2'],':sample3'=>$_POST['sample3'],':sample4'=>$_POST['sample4']));
	print_r($_POST['sample1'], $_POST['sample2'], $_POST['sample3'],$_POST['sample4']);
}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

将单引号(')更改为反引号(`)是解决方案。谢谢B_CooperA