高手帮忙!如何解决MYSQL语句在PHP里的难题?求救!!!

Flueye 2004-11-29 03:53:24
部分PHP代码如下:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
//从form里取得参数
$dept_main=GetSQLValueString($_POST['dept_main'],"text");
$eventdate=GetSQLValueString($_POST['eventdate'], "date");
$eventtime_start=GetSQLValueString($_POST['eventtime_start'], "text");
$eventtime_end=GetSQLValueString($_POST['eventtime_end'], "text");
$eventtime_remark=GetSQLValueString($_POST['eventtime_remark'], "text");
$event_addr=GetSQLValueString($_POST['event_addr'], "text");
$event_content=GetSQLValueString($_POST['event_content'], "text");
$event_done=GetSQLValueString($_POST['event_done'], "text");
$leader_name=GetSQLValueString($_POST['leader_name'], "text");
//很长的SQL查询语句 开始
$insertSQL="set @deptID := (SELECT dept_id FROM dept WHERE dept_main=".$dept_main.");
INSERT INTO event (eventdate, eventtime_start, eventtime_end, eventtime_remark, event_addr, event_content, event_done,dept_id)
VALUES (".$eventdate.",".$eventtime_start.",".$eventtime_end.",".$eventtime_remark.",".$event_addr.",".$event_content.",".$event_done.",@deptID);
set @eventID := (SELECT event_id FROM event WHERE event_id IS NULL);
set @leaderID := (SELECT leader_id FROM leader WHERE leader_name=".$leader_name.");
INSERT INTO event_leader (event_id, leader_id) values(@eventID,@leaderID)";//结束
//执行
mysql_select_db($database_mconn, $mconn);
$Result1 = mysql_query($insertSQL, $mconn) or die(mysql_error());
}

下面是错误输出:
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 '; INSERT INTO event (eventdate, eventtime_start, eventtime_en

用echo $insertSQL查询得:
set @deptID := (SELECT dept_id FROM dept WHERE dept_main='市委办'); INSERT INTO event (eventdate, eventtime_start, eventtime_end, eventtime_remark, event_addr, event_content, event_done,dept_id) VALUES ('8','8','8','88','8','8','n',@deptID); set @eventID := (SELECT event_id FROM event WHERE event_id IS NULL); set @leaderID := (SELECT leader_id FROM leader WHERE leader_name='LO'); INSERT INTO event_leader (event_id, leader_id) values(@eventID,@leaderID)
...全文
93 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Flueye 2004-11-29
不好意思,我简单点
部分PHP代码如下:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
...
$insertSQL="
set @eventID := (SELECT event_id FROM event WHERE event_id IS NULL);
set @leaderID := (SELECT leader_id FROM leader WHERE leader_name=".$leader_name.");
INSERT INTO event_leader (event_id, leader_id) values(@eventID,@leaderID)";

mysql_select_db($database_mconn, $mconn);
$Result1 = mysql_query($insertSQL, $mconn) or die(mysql_error());
}

下面是错误输出:
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 '; set @leaderID := (SELECT leader_id FROM leader WHERE leader
到底错在哪????
用echo $insertSQL查询得:
set @eventID := (SELECT event_id FROM event WHERE event_id IS NULL); set @leaderID := (SELECT leader_id FROM leader WHERE leader_name='LO'); INSERT INTO event_leader (event_id, leader_id) values(@eventID,@leaderID)
回复
jxflll 2004-11-29
好乱!
回复
相关推荐
发帖
基础编程
创建于2007-09-28

2.1w+

社区成员

从PHP安装配置,PHP入门,PHP基础到PHP应用
申请成为版主
帖子事件
创建了帖子
2004-11-29 03:53
社区公告
暂无公告