下面的代码以表格形式显示人员,并在每一行的末尾发送按钮,并与在搜索框中输入人员的条件相匹配。与该行相对应的发送按钮将行数据发送到geosendmail.php,现在的问题是我无法在mysql // doner查询中使用该数据,但是当我将该数据发布到段落元素时,数据显示起来很好!我尝试在控制台上监视代码流,一切正常。如果有错误,则控制台不会显示它。请帮我修复它
<?php
if(isset($_POST['searchbox'])){
$bloodonation =$_POST['searchbox'];
$multiple= explode(',',$bloodonation);
$var1 = $multiple[0]; // firstname
$var2 = $multiple[1]; // fathername
$var3 = $multiple[2]; // lastname /*bloodtype.blood_type='$var4' AND bodytype.bodytype='$var5' AND */
$_SESSION["firstname"] = $var1;
$_SESSION["fathername"] = $var2;
$_SESSION["lastname"] = $var3;
if(!empty($bloodonation)){
//$myfile = fopen("file.txt", "w");
//file_put_contents('file.txt',$bloodonation);
//fclose($myfile);
$bloodquery ="SELECT d.firstname AS donnerfirstname,d.fathername AS donnerfathername,d.lastname AS donnerlastname
FROM personprofile d,personprofile r
WHERE r.firstname = '$var1' AND r.fathername='$var2' AND r.lastname= '$var3' AND r.bloodtype=d.bloodtype
AND d.hascancer='No' AND d.chronicdisease='No' AND d.autoimmunedisease='No' AND d.substanceabuse=1
AND d.hospitaladmission=134 AND d.health_issues='No' AND
d.bloodonation_date=(SELECT MAX(d.bloodonation_date) FROM personprofile d)";
//$sql = "SELECT `firstname`, `fathername`, `lastname` FROM `personprofile` WHERE chronicdisease=\"No\" AND hascancer=\"No\" AND autoimmunedisease=\"No\"";
$bloodqr=mysqli_query($link,$bloodquery);
echo "<table id='tblId'>";
echo "<tr><th>Firstname</th><th>Fathername</th><th>Lastname</th></tr> ";
while($row=mysqli_fetch_assoc($bloodqr)){
echo"<tr><td>";
echo $row['donnerfirstname'];
echo "</td><td>";
echo $row['donnerfathername'];
echo "</td><td>";
echo $row['donnerlastname'];
echo "</td><td>";?><html><button id="myBtn" onclick="myFunction(this)">Send Email</button></html> <?php
echo"</td></tr>";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type= "text/javascript" src= "js/jquery.js" > </script>
<script>
var tbl = document.getElementById("tblId");
var tblbutton = document.getElementById("myBtn");
function myFunction(element) {
// alert(element.closest('tr').rowIndex);
var rowindex = element.closest('tr').rowIndex;//get the index of the row the button is on
var test= tbl.rows[rowindex].innerHTML; //get html data of row
var y= test.replace(/<(?:.|\n)*?>/gm, ' '); //get raw data
var z = y.split(' ').join(',');
var x = z.replace(',,,Send,Email,,,',' ');
var w = x.replace(',,', ',');
var t = w.replace(',,',',');
var q = t.replace(',','');
$.ajax({
type: 'POST',
url: 'geosendmail.php',
data: {donorname: q},
success: function(data) {
$("#demo").html(data);}
});
}
</script> </head>
<body>
<p id="demo"></p>
</body>
</html>
geosendmail.php
<?php
// Start the session
session_start();
?>
<?php
$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
if(isset($_POST['donorname'])){
$firstname=$_SESSION["firstname"];
$fathername=$_SESSION["fathername"];
$lastname=$_SESSION["lastname"];
$donorname = $_POST['donorname'];
$pieces = explode(",",$donorname);
$donorfirstname = $pieces[0];
$donorfathername = $pieces[1];
$donorlastname = $pieces[2];
$_SESSION["firstname"] = $donorfirstname;
$_SESSION["fathername"] = $donorfathername;
$_SESSION["lastname"] = $donorlastname;
$dfn = $_SESSION["firstname"];
$dfan= $_SESSION["fathername"];
$dln=$_SESSION["lastname"];
$pbloodtype="SELECT firstname,fathername,lastname,email,bloodoner
FROM personprofile
WHERE firstname='$dfn' AND fathername='$dfan' AND lastname='$dln'";
$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,hospital.hospitalname,hospital.geolocation
FROM personprofile,hospital
WHERE personprofile.firstname= '$firstname' AND personprofile.lastname= '$lastname' AND personprofile.fathername= '$fathername'
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"){ //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
}
}
?>