在mysql表中插入正斜杠的问题
我在将字符串“AM/PM”插入到 mySQL 表时遇到问题
$timeFormat = mysql_real_escape_string($_POST['timeFormat']);
$sql="
UPDATE profiles
SET firstName = '$firstName', lastName = '$lastName', language = '$language', timeFormat = '$timeFormat'
WHERE profileId = '$profileId'
";
mysql_query($sql) or die('Error: '.mysql_error());
没有错误,但该表仅显示 AM/?
编辑:
当我回显 $sql 时,我得到:
UPDATE profiles SET firstName = 'Johan', lastName = 'Lund', language = 'English', timeFormat = 'AM/PM' WHERE profileId = '27'
而且,是的,在问这个问题之前我已经在网上搜索了很长时间。如果您有来自 Stackoverflow 的任何链接,也许可以。我已经忽略了它。
I got problem inserting the string "AM/PM" to my mySQL table
$timeFormat = mysql_real_escape_string($_POST['timeFormat']);
$sql="
UPDATE profiles
SET firstName = '$firstName', lastName = '$lastName', language = '$language', timeFormat = '$timeFormat'
WHERE profileId = '$profileId'
";
mysql_query($sql) or die('Error: '.mysql_error());
There is no error, but the table is only showing AM/ ??
Edit:
When I echo the $sql I get:
UPDATE profiles SET firstName = 'Johan', lastName = 'Lund', language = 'English', timeFormat = 'AM/PM' WHERE profileId = '27'
And, yes I have searched the web in a very long time before asking this question. Probably if you have any link from Stackoverflow. I have already overlooked it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这个插入没有任何问题。
问题在于你如何看到查询结果。
nothing wrong with this insert.
it's matter of how do you see the query result.
检查数据库中的数据类型如果是 Varchar(3),则 MySQL 正在截断您的数据。
Check your datatype in the database If it's Varchar(3) then MySQL is truncating your data.
看起来斜杠在 INSERT 时进行了某种类型的转义。我假设它被你的 php 解释器解释为“恶意”。
运行这个:
让我知道结果。
Looks like that slash is doing some type of escape upon INSERT. I assume its being interpreted as "malicious" by your php interpreter.
Run this:
Let me know the result.
检查表的字符集和排序规则,如果它是 utf8 字符集和 utf8_bin 排序规则,我可以使用 TEXT 列修复此问题,而 latin1 在正斜杠后被截断。
Check your character set and collation for the table, I was able to fix this with a TEXT column if it is utf8 charset and utf8_bin collation, whereas latin1 was truncating after the forward slash.