Php 函数不';即使它返回真值,也不能工作
我正在创建一个在线献血管理网站。在网站的员工用户端,有一个“标记为完成”功能,用于记录献血者何时成功参加并完成预定的献血预约 员工用户单击“标记为完成”后,应发生以下情况:Php 函数不';即使它返回真值,也不能工作,php,function,Php,Function,我正在创建一个在线献血管理网站。在网站的员工用户端,有一个“标记为完成”功能,用于记录献血者何时成功参加并完成预定的献血预约 员工用户单击“标记为完成”后,应发生以下情况: TBLAPPOINTS中约会的“完成”列更新为1 捐赠用户收到通知,其预约已被员工用户标记为已完成 “bloodUnitsReceived”列的值增加1。(例如:如果患者到目前为止已收到2个血液单位,则新的献血将bloodUnitsReceived列更新为3) “收单机构”,即代表患者请求献血的与患者相关的用户,收到有人向其
1
bloodUnitsReceived
列更新为3)if(amtBloodUnitsRequired==bloodUnitsReceived)
)。如果是这样,则收单机构会收到通知,告知其患者/爱人已完成其规定的血液单位,并存档其献血请求
这是我做的函数:
function checkAndMarkPatientDone($conn,$patientID){
//check if patient has completed donations needed
$checkReceived = $conn->query("Select acquirerID,patientFN, patientMI, patientLN, amtBloodUnits, bloodUnitsReceived from tblpatient where id = '$patientID'");
if($checkReceived -> num_rows>0){
$bloodUnits= $checkReceived->fetch_all(MYSQLI_ASSOC);
foreach($bloodUnits as $blood){
$amtBloodUnits = $blood['amtBloodUnits'];
$bloodReceived = $blood['bloodUnitsReceived'];
$patientFullName = $blood['patientFN']." ".$blood['patientMI'].". ".$blood['patientLN'];
$acquirerID = $blood['acquirerID'];
}
//if blood units received have matched blood units needed
if($bloodReceived == $amtBloodUnits){
//update patient as complete
$update = "UPDATE tblpatient set completed = 1 where id = '$patientID'";
//archive blooddonation request
$archiveRequest = "UPDATE blooddonationrequest as r INNER JOIN tblpatient as p on r.patientID = p.id set archived = 1 where p.id = '$patientID'";
if(($conn->query($update)==TRUE) && ($conn->query($archiveRequest)==TRUE)) {
return true;
}
else{
return false;
}
}
else{
return false;
}
}
}
在这里,我调用函数,并在函数返回true时发送通知和电子邮件通知:
if(checkAndMarkPatientDone($conn,$patientID)==true){
//notify acquirer
$icon = "/WBBSD/header/done.png";
$notifTitle = "Your goal of reaching".$unitsNeeded." blood units for ".$patientName." has been reached!";
$notifMsg = "It\'s our pleasure in helping you find the blood your loved one needs. We pray for your loved one\'s healing!";
$usertype = "acquirer";
$acquirerID = $acquirerID;
if(addNotif($conn,$icon, $notifTitle, $notifMsg,$usertype,$acquirerID)==false){
$_SESSION['errorMsg'] = "Error notifying about blood completion.";
}
//send email to acquirer
$acquirerDetails = getAcquirerDetails($conn,$acquirerID);
$userEmail = $acquirerDetails['email'];
$userFullName = $acquirerDetails['firstName']." ".$acquirerDetails['middleInitial'].". ".$acquirerDetails['lastName'];
$emailResult = sendEmail($userEmail,$notifMsg,$userFullName,$notifTitle);
$_SESSION['informMsg'].="\n Acquirer Email Status: ".$emailResult;
}
我遇到的问题是,if(checkandmarkpatientsdone($conn,$patientID)==true)下的代码根本不运行。在它完成之前的所有代码和函数都可以运行(下面完成代码),但系统似乎忽略了这部分代码。起初我认为可能是checkandmarkpatientsdone()
函数没有返回true,因此我测试了该函数并在单独的PHP文件中调用它。在测试过程中,该函数确实成功运行并返回true,但当我将其与其他代码一起包含时,它就不起作用了
以下是员工点击献血预约“标记完成”按钮的完整代码,供您参考:
if (isset($_POST['btnDone'])) {
$requestID = $_POST['requestID'];
//need to know donor id to know who to add
$donorID = $_POST['donorID'];
//update that tblappointment is done
$updatequery = "UPDATE tblappointment SET completed = 1 where donationRequestID = '$requestID'";
if($conn->query($updatequery)==TRUE){
$_SESSION['successMsg'] = "Appointment successfully marked complete";
//record donation to patient and donor side
if(addDonation($conn,$donorID,$requestID) == TRUE){
$_SESSION['successMsg'].=" and donation recorded successfully";
//notify donor for completed appointment
$icon = "/WBBSD/header/blood-donation.png";
$notifTitle = "Your appointment was marked complete.";
$notifMsg = "Thank you for attending and completing your blood donation. Make sure to get enough rest and nutrients. Come back after 3 months!";
$usertype = "donor";
$donorID = $donorID;
if(addNotif($conn,$icon, $notifTitle, $notifMsg,$usertype,$donorID)==false){
$_SESSION['errorMsg'] = "Error with notifying donor.";
}//if addnotif flase
//send email to donor
$donorDetails = getDonorDetails($conn,$donorID);
$userEmail = $donorDetails['email'];
$userFullName = $donorDetails['firstName']." ".$donorDetails['middleInitial'].". ".$donorDetails['lastName'];
$_SESSION['informMsg'] ="Donor Email Status: ".sendEmail($userEmail,$notifMsg,$userFullName,$notifTitle);
//get patient details for acquirer notification
$patientresult = $conn->query("SELECT * FROM tblpatient as p INNER JOIN tblappointment as a on p.id = a.patientID where a.donationRequestID = '$requestID'");
if($patientresult -> num_rows>0){
$pDetails= $patientresult->fetch_all(MYSQLI_ASSOC);
foreach($pDetails as $pDetail){
$patientName = $pDetail['patientFN']." ".$pDetail['patientMI'].". ".$pDetail['patientLN'];
$apptDate = $pDetail['apptDate'];
$bloodReceived = $pDetail['bloodUnitsReceived'];
$bloodReceived = $pDetail['bloodUnitsReceived'];
$unitsNeeded = $pDetail['amtBloodUnits'];
$acquirerID = $pDetail['acquirerID'];
//for checking if donations are complete
$patientID = $pDetail['id'];
}//foreach pdetails
}//if patientresult
//notify acquirer for new donation
$icon = "/WBBSD/header/help.png";
$notifTitle = "Your loved one has received a blood donation!.";
$notifMsg = "One of our registered blood donors has successfully donated blood for your loved one, ".$patientName." on ".$apptDate.". Your request has received ".$bloodReceived."/".$unitsNeeded." blood units so far.";
$usertype = "acquirer";
$acquirerID = $acquirerID;
if(addNotif($conn,$icon, $notifTitle, $notifMsg,$usertype,$acquirerID)==false){
$_SESSION['errorMsg'] = "Error with notifying donor.";
}//if addnotif flase
//send email to acquirer
$acquirerDetails = getAcquirerDetails($conn,$acquirerID);
$userEmail = $acquirerDetails['email'];
$userFullName = $acquirerDetails['firstName']." ".$acquirerDetails['middleInitial'].". ".$acquirerDetails['lastName'];
$_SESSION['informMsg'].="\n Acquirer Email Status: ".sendEmail($userEmail,$notifMsg,$userFullName,$notifTitle);
//check if reached blood goal
if(checkAndMarkPatientDone($conn,$patientID)==true){
//notify acquirer
$icon = "/WBBSD/header/done.png";
$notifTitle = "Your goal of reaching".$unitsNeeded." blood units for ".$patientName." has been reached!";
$notifMsg = "It\'s our pleasure in helping you find the blood your loved one needs. We pray for your loved one\'s healing!";
$usertype = "acquirer";
$acquirerID = $acquirerID;
if(addNotif($conn,$icon, $notifTitle, $notifMsg,$usertype,$acquirerID)==false){
$_SESSION['errorMsg'] = "Error notifying about blood completion.";
}
//send email to acquirer
$acquirerDetails = getAcquirerDetails($conn,$acquirerID);
$userEmail = $acquirerDetails['email'];
$userFullName = $acquirerDetails['firstName']." ".$acquirerDetails['middleInitial'].". ".$acquirerDetails['lastName'];
$emailResult = sendEmail($userEmail,$notifMsg,$userFullName,$notifTitle);
$_SESSION['informMsg'].="\n Acquirer Email Status: ".$emailResult;
}//if check
//everything successful
header("location: ../staff/staff_dash.php");
}
else{
$_SESSION['errorMsg']="Failed to record donation";
}
}
else{
$_SESSION['errorMsg'] = "Unable to mark appointment complete. Please try again.";
}
}
有什么问题吗?忽略所有SQL注入问题,我们不知道什么是$conn
,这可以说是最重要的细节,它是PDO实例吗?哦,对不起,$conn拥有到我收集的数据库的连接,但这仍然没有帮助。它是什么,mysqli
对象,PDO
,ORM处理程序?您需要更精确地提供哪些信息,并减少信息量,因为很多信息似乎都是不必要的。这是一个mysqli objectRight,首先,mysqli
的查询方法永远不会返回true,它要么是false
或者mysqli\u结果
,因此检查true
是一个很好的选择有点奇怪,虽然这不是问题,因为你做的比较很弱。问题是你是否“进入”了这个if块:if($bloodReceived==$amtBloodUnits){