用php mysql插入查询问题

Mee*_*ena 2 php mysql

这很简单我使用以下插入查询

mysql_query(insert into table1 set saltval = 'Y'Z' where uid ='1');
Run Code Online (Sandbox Code Playgroud)

但我不工作因为盐田的价值是Y'Z.我的问题是如何将此值视为字符串.

Jac*_*cob 5

您需要使用反斜杠转义任何单引号.

mysql_query("insert into table1 set saltval = 'Y\'Z' where uid ='1'");
Run Code Online (Sandbox Code Playgroud)

但是你的SQL也是无效的...你的意思是做更新吗?插入语句没有where.

如其他答案中所述,如果输入来自用户,则应使用mysql_real_escape_string()
http://www.php.net/manual/en/function.mysql-real-escape-string.php