我有这个医院应用程序,可以在其中键入特定患者的姓名,并且应该根据其血型返回可能的供体匹配。
问题是,当我单击发送按钮时,它会将其发送到所有结果,所有结果都有相同的电子邮件进行测试,但真实收件人,患者姓名和详细信息除外,尽管多次出现正确
这是我的代码
$link= new mysqli('localhost','root','');
if($link->connect_error){
die("Connection failed:" .$link->connect_error);
}
mysqli_select_db($link,"blood_organ_donation");
$sendtoperson= $_POST['send']; //send message to person found from search result
//Take contents of the search box
//mail function parameters, send two sets of messages depending on blood/organ donation
$firstname=$_SESSION["firstname"];
$fathername=$_SESSION["fathername"];
$lastname=$_SESSION["lastname"];
$pbloodtype="SELECT personprofile.firstname,personprofile.lastname,personprofile.fathername,personprofile.email,bloodtype.blood_type,personprofile.bloodoner
FROM personprofile,bloodtype
WHERE personprofile.bloodtype=bloodtype.id AND personprofile.hospitaladmission=134 ";
$fetchbloodtype= mysqli_query($link,$pbloodtype); //doner query
$processblood=mysqli_fetch_assoc($fetchbloodtype);
while($processblood= mysqli_fetch_assoc($fetchbloodtype)){
$query ="SELECT personprofile.firstname,personprofile.fathername,personprofile.lastname,bloodtype.blood_type,hospital.hospitalname,hospital.geolocation
FROM personprofile,bloodtype,hospital
WHERE firstname= '$firstname' AND lastname= '$lastname' AND fathername= '$fathername'
AND personprofile.bloodtype=bloodtype.id AND personprofile.hospitaladmission=hospital.id";
$fetchemail= mysqli_query($link,$query); //patient query
$process=mysqli_fetch_assoc($fetchemail);
// Send the blood donation email if person is blood donner
if($processblood['bloodoner']=="Yes" && $processblood['blood_type']==$process['blood_type']){ //with same bloodtype
$to=$processblood['email'];
$header= "Blood is needed urgently";
// $messagebody= "Patient Name: ".$processtable['firstname']." ".$processtable['fathername']." ".$processtable['lastname']." "."Hospital Name:";
$messagebody = "Patient Name: ".$process['firstname']." ".$process['fathername']." ".$process['lastname']." "."Hospital Name:".PHP_EOL;
//$hyperlink= new DOMDocument();
//$hyperlink->loadHTML("<html><body><a href='<".$processtable['geolocation']."'>" .$processtable['hospitalname']."</a></body></html>");
$hyperlink = "<html><body><a href='<".$process['geolocation']."'>".$process['hospitalname']."</a></body></html>".PHP_EOL;
//Name of the person that needs the blood transfusion along with hospital he is staying at,hyperlinked to its location
$string .= $messagebody." ".$hyperlink.PHP_EOL ;
$message= "Dear"." ".$processblood['firstname']." ".$processblood['lastname'].",".PHP_EOL .$string;
if(isset($sendtoperson)){
if(mail($to,$header,$message)){
echo "Sent";
}
else{ echo "Not sent";}
}
}//end of if person was blooddoner
}