我的代码是将表单中发布的值插入表中。 代码:
1 $email1 = $_POST['txtemail'];
2 $user1 = $_POST['txtuser'];
3 $date1 = $_POST['txtdate'];
4 $subject1 = $_POST['txtsubject'];
5 $percent = $_POST['txtpercent'];
6 $percent1 = (string) $percent;
7 $query = "insert into personal_record values '','$email1','$user1','$date1','$subject1','$percent1'";
8 $result = mysql_query($query,$link);
这是我的代码,它给出了错误:
您的SQL语法有错误; 检查对应的手册 您的MySQL服务器版本 正确的语法使用附近 '' ' 'jugal_patel2007 @ yahoo.co.in', '颧骨',' 29 2011年3月13:28:42','jquery','40'' 第1行
请尽快帮助我......! 请帮忙。
答案 0 :(得分:2)
您需要在值列表周围括号:
insert into personal_record
values ('','jugal_patel2007@yahoo.co.in','Jugal','29 Mar 2011 13:28:42','jquery','40')
而且,作为旁注,您必须使用mysql_real_escape_string()
逃避数据,以防止SQL Injections!
所以,在这里,你可能会得到一些看起来有点像这样的东西:
$email1_safe = mysql_real_escape_string($_POST['txtemail']);
$user1_safe = mysql_real_escape_string($_POST['txtuser']);
$date1_safe = mysql_real_escape_string($_POST['txtdate']);
$subject1_safe = mysql_real_escape_string($_POST['txtsubject']);
$percent_safe = mysql_real_escape_string($_POST['txtpercent']);
$percent1_safe = mysql_real_escape_string((string) $percent);
$query = "insert into personal_record values ('','$email1_safe','$user1_safe','$date1_safe','$subject1_safe','$percent1_safe')";
$result = mysql_query($query,$link);
附加说明:
答案 1 :(得分:1)
更改查询var:
$query = "insert into personal_record values
('','$email1','$user1','$date1','$subject1','$percent1');";
根据@ Pekka的建议:
您缺少括号:它必须是VALUES ( ..... )
答案 2 :(得分:0)
您可以从值旁边放置括号:
"insert into personal_record values ('','$email1','$user1','$date1','$subject1','$percent1')"