我会承认我是PDO的新手,但是我必须改变mysql中的一个表格。我正在接通,但没有插入..我真的被卡住了,感觉像个白痴,因为我知道这很简单,我不知道
我已尝试在插入之上和之后使用数组..两者都没有工作
任何帮助将不胜感激
这是我的代码:
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
$STH = $conn->prepare("INSERT INTO PinTrade (ID, PIN, Year, Make, Model, Mileage, FirstName, LastName, Phone, Email, Date)
VALUES ('', '$pin', '$year', '$make', '$model', '$mileage', '$first', '$last', '$phone', '$email', '1234' )");
$STH->bindParam(':PIN', $_POST['pin']);
$STH->bindParam(':Year', $_POST['year']);
$STH->bindParam(':Make', $_POST['make']);
$STH->bindParam(':Model', $_POST['model']);
$STH->bindParam(':Mileage', $_POST['mileage']);
$STH->bindParam(':FirstName', $_POST['first']);
$STH->bindParam(':LastName', $_POST['last']);
$STH->bindParam(':Phone', $_POST['phone']);
$STH->bindParam(':Email', $_POST['email']);
$STH->execute();
答案 0 :(得分:1)
删除查询值中的美元符号和引号:
$STH = $conn->prepare("INSERT INTO PinTrade (ID, PIN, Year, Make,
Model, Mileage, FirstName, LastName, Phone, Email, Date)
VALUES (null, :PIN, :Year, :Make, //and so on....
另请注意,假设ID是自动递增字段,只需插入null
VALUES (null, :PIN,
最后,如果您从帖子数组中撤出,我会bindValue
使用bindParam