这很简单,我正在使用以下插入查询
mysql_query(insert into table1 set saltval = 'Y'Z' where uid ='1');
但我不起作用,因为字段 saltval 的值为 Y'Z 。我的问题是如何将此值视为字符串。
最佳答案
您需要使用反斜杠转义任何单引号。
mysql_query("insert into table1 set saltval = 'Y\'Z' where uid ='1'");
但是您的 SQL 也无效...您是要进行更新吗?插入语句没有位置。
正如其他答案中提到的,如果输入来自用户,那么您应该使用 mysql_real_escape_string()
http://www.php.net/manual/en/function.mysql-real-escape-string.php
关于php - php mysql插入查询问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4978071/