Hello guys I have this code that displays mysql data in a table,which it does, I want to take the data from the cells,which it does, and use an ajax request to post the data to a php file,which it doesn't, and the data retrieved to be displayed in a paragraph tag,just for testing. When I take the cell data and post it to an alert in works.
What am I doing wrong
test.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,bloodtype.blood_type,bodytype.bodytype,MAX(d.bloodonation_date)
FROM personprofile d,personprofile r,bloodtype,bodytype
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'";
//$sql = "SELECT `firstname`, `fathername`, `lastname` FROM `personprofile` WHERE chronicdisease=\"No\" AND hascancer=\"No\" AND autoimmunedisease=\"No\"";
$bloodqr=mysqli_query($link,$bloodquery);
echo "<table>";
echo "<tr><th>Firstname</th><th>Fathername</th><th>Lastname</th><th>Blood type</th><th>Body type</th></tr> ";
while($row=mysqli_fetch_assoc($bloodqr)){
echo"<tr><td id='dfirstname'>";
echo $row['donnerfirstname'];
echo "</td><td id='dfathername'>";
echo $row['donnerfathername'];
echo "</td><td id='dlastname'>";
echo $row['donnerlastname'];
echo "</td><td id='dbloodtype'>";
echo $row['blood_type'];
echo "</td><td id='dbodytype'>";
echo $row['bodytype'];
echo "</td><td>";?><html><button onclick="outputdata()">Send Email</button></html> <?php
echo"</td></tr>";
}
}
} ?>
<!DOCTYPE html>
<html>
<head>
<script>
var donorfirstname = document.getElementById("dfirstname");
var dfn = donorfirstname.innerHTML;
var donorfathername = document.getElementById("dfathername");
var dfan = donorfathername.innerHTML;
var donorlastname = document.getElementById("dlastname");
var dln= donorlastname.innerHTML;
var donorbloodtype = document.getElementById("dbloodtype");
var dbt=donorbloodtype.innerHTML;
var donorbodytype = document.getElementById("dbodytype");
var dbot= donorbodytype.innerHTML;
function outputdata() {
$.ajax({
type: 'POST',
url: 'mytest.php',
data: {dofirstname: dfn,dofathername:dfan,dolastname:dln,dobloodtype:dbt,dobodytype:dbot},
success: function(data) {
$("#demo").html(data);}
});
//alert(dfn+dfan);//this works when uncommented
}
</script> </head>
<body>
<p id="demo"></p>
</body>
</html>
mytest.php