gpt4 book ai didi

php - MySQL语法错误

转载 作者:行者123 更新时间:2023-11-29 02:35:30 25 4
gpt4 key购买 nike

我正在尝试将一个具有很长字符串的 php 变量插入到 mysql 数据库中。我一直遇到这个错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near line of text from string line 2

这是我用来插入的代码:

$sql = mysql_query("INSERT INTO myResumes (resumeid, rawresumetext) 
VALUES('$resumeid', $rawresumetext)")
or die (mysql_error());

我该如何避免这种情况?

最佳答案

可能是因为您忘记引用 $rawresumetext。也不要忘记通过 mysql_real_escape_string()

传递这两个变量
$resumeid = mysql_real_escape_string($resumeid);
$rawresumetext = mysql_real_escape_string($rawresumetext);

$sql = mysql_query("INSERT INTO myResumes (resumeid, rawresumetext)
VALUES('$resumeid', '$rawresumetext')")
or die (mysql_error());

关于php - MySQL语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5722456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com