[英]PHP MySQL "DELETE FROM `table` WHERE `id` = | unknown column `id`
My Code: 我的代码:
if (isset($_POST['del'])) {
foreach ($_POST['del'] as $id){
if ($stmt = $mysqli->prepare("DELETE FROM `users` WHERE `̌id` = ?")) {
$stmt->bind_param('i', $id);
$stmt->execute();
} else {
printf("Errormessage: %s<br>", $mysqli->error);
}
}
}
Result: Errormessage: Unknown column '̌id' in 'where clause'
结果:
Errormessage: Unknown column '̌id' in 'where clause'
$_POST['del']
contains integers from checkboxes of a form. $_POST['del']
包含来自表单复选框的整数。
However, this is used with the same connection earlier, and it works: 但是,这与先前的相同连接一起使用,并且可以工作:
$modified = arrayRecursiveDiff($_POST, $data);
foreach($modified as $key => $val_arr) {
if (!is_array($val_arr)) {continue;}
foreach ($val_arr as $iteration => $val) {
$id = $iteration + 1;
$query = 'UPDATE users
SET '. $key .'="'. $val .'"
WHERE id = '. $id;
if (preg_match('/.*\sdel\=.*/',$query) === 0){
$mysqli->query($query);
}
}
}
Funniest thing is that I tried to echo that query and copy it directly into mysql command prompt. 最有趣的是,我试图回显该查询并将其直接复制到mysql命令提示符中。 It worked perfectly...
效果很好...
I would appreciate if someone had an answer to what could possibly be going wrong here, 如果有人对这里可能发生的问题有一个答案,我将不胜感激,
It seems like there's some weird character ( Edit: consult Footnotes ) that resembles a backtick just before id
, but in fact isn't. 似乎有些奇怪的字符( 编辑:请查阅Footnotes )类似于
id
之前的反引号,但实际上不是。
I couldn't tell exactly from my editor, yet. 我还无法从编辑器中确切得知。 ( Edit: consult Footnotes )
( 编辑:查阅脚注 )
Change this line: 更改此行:
if ($stmt = $mysqli->prepare("DELETE FROM `users` WHERE `̌id` = ?")) {
to 至
if ($stmt = $mysqli->prepare("DELETE FROM `users` WHERE `id` = ?")) {
I just went into EDIT mode again (11:00 pm EDT) after you edited your question with the updated code and I copy/pasted your query line into my editor, and there is still a strange character between your first backtick and the word id
. 在您使用更新的代码编辑问题之后,我刚刚再次进入编辑模式(美国东部时间下午11:00),我将查询行复制/粘贴到了我的编辑器中,并且在第一个反引号和
id
单词之间仍然有一个奇怪的字符。
if ($stmt = $mysqli->prepare("DELETE FROM `users` WHERE `̌id` = ?")) {
^^
Copy/paste this actual code in your file. 将实际代码复制/粘贴到文件中。 But I'm curious to know which file editor you're using that is causing this, or are you typing this by hand?
但是我很好奇您正在使用哪个文件编辑器导致此问题,或者您是手动键入此文件?
if (isset($_POST['del'])) {
foreach ($_POST['del'] as $id){
if ($stmt = $mysqli->prepare("DELETE FROM `users` WHERE `id` = ?")) {
$stmt->bind_param('i', $id);
$stmt->execute();
} else {
printf("Errormessage: %s<br>", $mysqli->error);
}
}
}
From what I found in my editor, it seemed to be ( either ) this unicode character ‎
从我在编辑器中发现的内容来看,这似乎是( 要么 )这个Unicode字符
‎
that was before id
那是在
id
之前
Unicode hex: 8206 Unicode十六进制:8206
Unicode decimal: 33286 Unicode十进制:33286
UTF-8 Hex: e88886 UTF-8十六进制:e88886
HTML Entity: 舆 HTML实体:舆情
Source: http://www.htmlescape.net/82/character_8206.html 来源: http : //www.htmlescape.net/82/character_8206.html
or this from: http://en.wikipedia.org/wiki/Left-to-right_mark 或来自以下网站: http : //en.wikipedia.org/wiki/Left-to-right_mark
I quote: "The LRM causes the punctuation to be adjacent to only LTR text – the "C" and the LRM mark – and hence position as if it were in left-to-right text, ie, to the right of the preceding text. ‎
or ‎
may be required by some software rather than the invisible Unicode character itself; the actual invisible character would also make copy editing difficult. " 我引用:“ LRM使得标点符号仅与LTR文本(“ C”和LRM标记)相邻,因此其位置就好像它在从左到右的文本中一样,即在上一个文本的右边某些软件可能会要求
‎
或‎
而不是不可见的Unicode字符本身; 实际的不可见字符也会使复制编辑变得困难。
Added note: The Wikipedia information I found on the subject, I originally found while doing a Google search, which led me to this page which led me to The Wikipedia page I posted just above. 补充说明:我最初在进行Google搜索时发现的关于该主题的Wikipedia信息,这使我进入了该页面 , 该页面使我进入了我在上面发布的Wikipedia页面 。
Another Unicode character that was in the original question was ̌
原始问题中的另一个Unicode字符是
̌
From unicodemap.org and I quote: "Unicode Character Map - 0x036F (aka "̌")"
我从unicodemap.org引用:
"Unicode Character Map - 0x036F (aka "̌")"
Unicode Hexadecimal: 0x030C
Unicode Decimal: 780
UCS-2 Hexadecimal: 0x0C03
UCS-2 Decimal: 3075
HTML Hexadecimal: ̌
HTML Decimal: ̌
Character (which may be a bit hard to see): 字符(可能很难看):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.