I have this error: PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined.
And this is the code:
$query = "INSERT INTO ucp_beschwerde (date, tat_name, opfer_name, vergehen, content, one-url, two-url, three-url) VALUES (:date, :tat_name, :opfer_name, :vergehen, :content, :one-url, :two-url, :three-url)";
$smt = $db->prepare($query);
$smt->execute(array(':date' => $date, ':tat_name' => $_POST['beschuldigter'], ':opfer_name' => $aaa['Name'], ':vergehen' => $_POST['vergehen'], ':content' => $_POST['content'], ':one-url' => $_POST['one-bild'], ':two-url' => $_POST['two-bild'], ':three-url' => $_POST['three-bild']));
Table and columns containing hyphens must be wrapped in backticks.
SQL thinks you want to do math, which is being silently interpreted as " one
minus url
" etc.
Therefore, you either change your code to the following:
(date, tat_name, opfer_name, vergehen, content, `one-url`, `two-url`, `three-url`)
or rename your columns by changing the hyphens to underscores _
.
(date, tat_name, opfer_name, vergehen, content, one_url, two_url, three_url)
For more information on identifiers, visit:
Quoting the manual:
If any components of a multiple-part name require quoting,
quote them individually rather than quoting the name as a whole.
For example, write `my-table`.`my-column`, not `my-table.my-column`.
See Bill Karwin's answer also.
Pulled from Bill's answer:
Yes, you can use punctuation, white space, international characters, and SQL reserved words if you use delimited identifiers :
SELECT * FROM `my-table`;
In MySQL, use the back-ticks. In standard SQL, use double-quotes.
Or if you use MySQL you can set the ANSI_QUOTES
SQL mode :
SET SQL_MODE = ANSI_QUOTES;
SELECT * FROM "my-table";
Add $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
right after the connection is opened, if you are not already doing so.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.