简体   繁体   English

我无法在数据库中插入外键

[英]I can't insert a foreign key into my database

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\\xampp\\htdocs\\Buchhandlung\\gut.php on line 144 SQL Fehler in: INSERT INTO tblbücher (Titel, ISBN, Herausgabedatum, fVerlageID) VALUES(?, ?, ?, (Select VerlageID FROM tblverlage Where Name='Yen On')) 警告:PDOStatement :: execute():SQLSTATE [HY093]:无效的参数编号:绑定变量的数量与第144行SQL Fehler中的C:\\ xampp \\ htdocs \\ Buchhandlung \\ gut.php中的令牌数量不匹配:INSERT INTO tblbücher(Titel,ISBN,Herausgabedatum,fVerlageID)VALUES(?,?,?,(从tblverlage中选择VerlageID,其中Name =“ Yen On”))

This is what my browser says as an error, but I don't know what I am doing wrong. 这就是我的浏览器所说的错误,但是我不知道我在做什么错。 I try to insert data into my table "tblbücher". 我尝试将数据插入“tblbücher”表中。 The problem is, that I need to insert a foreign key but I cant display just "1, 2, 3, 4, 5,..." in the input form 问题是,我需要插入一个外键,但是我无法在输入表单中仅显示“ 1、2、3、4、5,...”

    if ($titel!="" and $isbn!="" and $herausgabedatum!="" and $verlage!="" )
    {
    $sql=$dbh->prepare("INSERT INTO tblbücher (Titel, ISBN, Herausgabedatum, fVerlageID) VALUES(?, ?, ?, (Select VerlageID FROM  tblverlage Where Name='$verlage'))");
    $sql->execute(array($titel, $isbn, $herausgabedatum, $verlage)) or die("SQL Fehler in: ".$sql->queryString." <br /> ".$sql->errorInfo()[2]);
    echo"<h1>Folgende Daten wurden der Tabelle Orte hinzugefügt:</h1></br> ";
    echo "<table>";
    echo

"<tr><th>Titel</th><th>Herausgabedatum</th><th>Name des Verlags</th><th>fVerlageID</th></tr>";
echo "<tr><td>$titel</td><td>$isbn</td><td>$herausgabedatum</td><td>$verlage</td></tr>";

}

This is how my input form looks like. 这是我的输入表单的样子。 You see that I need to call the "Verlag" "Yen On" instead of the foreign key "1" because it looks much better, but it doesn't work 您会发现我需要将“ Verlag”称为“ Yen On”,而不是外键“ 1”,因为它看起来要好得多,但它不起作用

You're saying you need three variables in your PDO 您是说在PDO中需要三个变量

VALUES(?, ?, ?, ...)

But you're specifying four 但是您要指定四个

$sql->execute(array($titel, $isbn, $herausgabedatum, $verlage))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM