基本上,登录用户应该只能提交一次首选项,然后从表中进行编辑。
if(isset($_POST['userPrefSave'])){
$studetnPrefId=$_POST['studentPrefId'];
$studentId=$_POST['studentId'];
$result= limitUserPref($studentPrefId,$studentId);
//print_r($result);
if(isset($result)< 1){
$studentPrefId=$_POST['studentPrefId'];
$studentId=$_POST['studentId'];
$english=$_POST['english'];
$math=$_POST['math'];
$science=$_POST['science'];
$history=$_POST['history'];
$oralComm=$_POST['oralComm'];
$pe=$_POST['pe'];
$health=$_POST['health'];
$art=$_POST['art'];
$electives=$_POST['electives'];
setUserPref($studentPrefId, $studentId, $english, $math, $science, $history, $oralComm, $pe, $health, $art, $electives);
header ("Location: userpref.php");
}
}
这是控制器^^^
function setUserPref($studentPrefId, $studentId, $english, $math, $science, $history, $oralcomm, $pe, $health, $art, $electives){
DB::insertUpdate('student_pref', array(
'student_pref_id'=>$studentPrefId
,'student_id'=>$studentId
,'english'=>$english
,'math'=>$math
,'science'=>$science
,'history'=>$history
,'oral_comm'=>$oralcomm
,'pe'=>$pe
,'health'=>$health
,'art'=>$art
,'electives'=>$electives));
}
function getStudentPref($studentID){
return DB::query("SELECT * FROM student_pref WHERE student_id = %d", $studentID);
}
function limitUserPref($studentPrefId, $studentId) {
return DB::query("SELECT * FROM student_pref WHERE student_pref_id = %d and student-id= %d", $studentPrefId, $studentId);
}
功能^^^
我不知道提前有什么问题
答案 0 :(得分:0)
看起来你正在做的检查是错误的。 isset()将确定变量是否已设置且不为NULL。
有关php isset http://php.net/manual/en/function.isset.php
的更多信息您正在检查将永远是真的
if(isset($result)< 1){
尝试以下
if(isset($_POST['userPrefSave'])){
$studetnPrefId=$_POST['studentPrefId'];
$studentId=$_POST['studentId'];
$result= limitUserPref($studentPrefId,$studentId);
//print_r($result);
if(count($result) < 1){
$studentPrefId=$_POST['studentPrefId'];
$studentId=$_POST['studentId'];
$english=$_POST['english'];
$math=$_POST['math'];
$science=$_POST['science'];
$history=$_POST['history'];
$oralComm=$_POST['oralComm'];
$pe=$_POST['pe'];
$health=$_POST['health'];
$art=$_POST['art'];
$electives=$_POST['electives'];
setUserPref($studentPrefId, $studentId, $english, $math, $science, $history, $oralComm, $pe, $health, $art, $electives);
header ("Location: userpref.php");
}
}