PHP MYSQL Insert into with switch语句
首先,我很抱歉,因为我还是一个新手,想学习更多关于编码的知识 我现在正在做这个。 我的第一、第二和第三张桌子工作正常。我的问题是我的第四个表没有收到任何值。 我试图用switch语句在第四个表中插入数据,其中$eGrad等于Grade Level。 我想在我的st_grade表(第四个表)中插入基于等级的值,其中一些是常量值 我将感谢任何帮助。谢谢 这是我正在使用的代码PHP MYSQL Insert into with switch语句,php,mysql,sql,switch-statement,sql-insert,Php,Mysql,Sql,Switch Statement,Sql Insert,首先,我很抱歉,因为我还是一个新手,想学习更多关于编码的知识 我现在正在做这个。 我的第一、第二和第三张桌子工作正常。我的问题是我的第四个表没有收到任何值。 我试图用switch语句在第四个表中插入数据,其中$eGrad等于Grade Level。 我想在我的st_grade表(第四个表)中插入基于等级的值,其中一些是常量值 我将感谢任何帮助。谢谢 这是我正在使用的代码 public function insert($stID, $eFullname, $eGrad, $secID, $eSta
public function insert($stID, $eFullname, $eGrad, $secID, $eStatus, $eSY, $syID, $rformOne, $rformTwo, $rPsa, $rGm, $rPic){
$firstTB = "INSERT INTO st_enrolled (e_stid, e_fullname,e_grade,e_status,e_sy) VALUES('$stID', '$eFullname', '$eGrad', '$eStatus', '$eSY')";
$secondTB = "INSERT INTO st_sy (st_sy_stid, st_sy_syid) VALUES('$stID', '$syID')";
$thirdTB = "INSERT INTO st_requirement (str_id, str_fullname, formOne, formTwo, psa, goodmoral, picture) VALUES ('$stID', '$eFullname', '$rformOne', '$rformTwo', '$rPsa', '$rGm', '$rPic')";
switch($eGrad){
case "Grade1" :
$fourthTB = "INSERT INTO `st_grade`(`st_id`,`subj_id`,`gr_id`,`sec_id`,`sy_id`,`first`,`second`,`third`,`fourth`,`ave`,`remarks`) VALUES
($stID, 1, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 2, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 3, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 4, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 5, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 6, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 7, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),";
break;
case "Grade2" :
$fourthTB = "INSERT INTO `st_grade`(`st_id`,`subj_id`,`gr_id`,`sec_id`,`sy_id`,`first`,`second`,`third`,`fourth`,`ave`,`remarks`) VALUES
($stID, 8, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 9, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 10, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 11, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 12, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 13, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 14, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),";
break;
default:
echo "error";
}
if ($this->conn->query($firstTB) && $this->conn->query($secondTB) && $this->conn->query($thirdTB) && $this->conn->query($fourthTB) ) {
return true;
} else {
return false;
}
}
我已经删除了sql字符串中的最后一个逗号,现在应该可以了
public function insert($stID, $eFullname, $eGrad, $secID, $eStatus, $eSY, $syID, $rformOne, $rformTwo, $rPsa, $rGm, $rPic){
$firstTB = "INSERT INTO st_enrolled (e_stid, e_fullname,e_grade,e_status,e_sy) VALUES('$stID', '$eFullname', '$eGrad', '$eStatus', '$eSY')";
$secondTB = "INSERT INTO st_sy (st_sy_stid, st_sy_syid) VALUES('$stID', '$syID')";
$thirdTB = "INSERT INTO st_requirement (str_id, str_fullname, formOne, formTwo, psa, goodmoral, picture) VALUES ('$stID', '$eFullname', '$rformOne', '$rformTwo', '$rPsa', '$rGm', '$rPic')";
switch($eGrad){
case "Grade1" :
$fourthTB = "INSERT INTO `st_grade`(`st_id`,`subj_id`,`gr_id`,`sec_id`,`sy_id`,`first`,`second`,`third`,`fourth`,`ave`,`remarks`) VALUES
($stID, 1, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 2, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 3, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 4, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 5, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 6, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 7, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, '')";
break;
case "Grade2" :
$fourthTB = "INSERT INTO `st_grade`(`st_id`,`subj_id`,`gr_id`,`sec_id`,`sy_id`,`first`,`second`,`third`,`fourth`,`ave`,`remarks`) VALUES
($stID, 8, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 9, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 10, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 11, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 12, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 13, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 14, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, '')";
break;
default:
echo "error";
}
if ($this->conn->query($firstTB) && $this->conn->query($secondTB) && $this->conn->query($thirdTB) && $this->conn->query($fourthTB) ) {
return true;
} else {
return false;
}
}
结尾的逗号会导致问题 以前
($stID, 7, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),";
($stID, 14, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),";
之后
在两种切换情况下,删除结尾处的逗号(,),这样做很好打字问题不应回答,而应标记为该问题(
标记
问题下的链接>“需要改进”>“社区特定原因”>“不可复制或由打字造成”),除了留下一条评论,指示OP问题的原因。不应回答打字错误问题,应将其标记为该问题(Flag
问题下的链接>“需要改进”>“社区特定原因”>“不可复制或由打字错误引起”),同时留下一条评论,说明问题的原因。到底是什么问题?你的问题到底是什么?检查如何
($stID, 7, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, '')";
($stID, 14, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, '')";