gpt4 book ai didi

php - 尝试限制表单提交的数量

转载 作者:行者123 更新时间:2023-11-29 21:19:20 26 4
gpt4 key购买 nike

因此,本质上,登录用户应该只能提交一次他们的首选项,然后从表中进行编辑。

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");
}
}

这是 Controller ^^^

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);

}

函数^^^

我不知道出了什么问题,提前致谢

最佳答案

看来您所做的检查是错误的。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");
}
}

关于php - 尝试限制表单提交的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35777691/

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