0

my code is supposed to send to the organ donor & blood donor depending on which he is an email with the name of the patient and hospital he is staying at. However if I put 2 people in the hospital with the same attributes as the person doing the donation .Supposed to append $messagebody and $hyperlink to $message It gives me this error - Parse error: syntax error, unexpected '$message' (T_VARIABLE), expecting ';' in C:\wamp\www\bloodonation\geosendmail.php on line 58 Please help me. This is my code

    $query ="SELECT email,bloodoner,organdoner,bloodtype,bodytype
        FROM personprofile
        WHERE   firstname= '$firstname' AND lastname= '$lastname' AND fathername= '$fathername'";
        $fetchemail=  mysqli_query($link,$query);
        $process=mysqli_fetch_assoc($fetchemail);

        $pbloodtype="SELECT personprofile.bloodtype,personprofile.firstname,personprofile.lastname,personprofile.fathername,hospital.hospitalname
        FROM personprofile,hospital,areaname 
        WHERE areaname.id= hospital.area AND personprofile.hospitaladmission= hospital.id AND areaname.area='$city'";
        $fetchbloodtype=  mysqli_query($link,$pbloodtype);
        $processblood=mysqli_fetch_assoc($fetchbloodtype);
        // Send the blood donation email if person is blood donner
        if($process['bloodoner']=="Yes" && $processblood['bloodtype']==$process['bloodtype']){ //with same bloodtype
        $to=$process['email'];
        $header= "Blood is urgently needed";
        $phquery="SELECT personprofile.firstname,personprofile.lastname,personprofile.fathername,hospital.hospitalname,hospital.geolocation 
        FROM personprofile,hospital,areaname 
        WHERE areaname.id= hospital.area AND personprofile.hospitaladmission= hospital.id AND areaname.area='$city'";
        $fetchospitalperson=  mysqli_query($link,$phquery);
        $processtable=mysqli_fetch_assoc($fetchospitalperson);
        do{
        $messagebody= "Patient Name: ".$processtable['firstname']." ".$processtable['fathername']." ".$processtable['lastname']."  "."Hospital Name:"; 

        //$hyperlink= new DOMDocument();
        //$hyperlink->loadHTML("<html><body><a href='<".$processtable['geolocation']."'>" .$processtable['hospitalname']."</a></body></html>"); 
        $hyperlink= "<html><body><a href='<".$processtable['geolocation']."'>".$processtable['hospitalname']."</a></body></html>";
         //Name of the person that needs the blood transfusion along with hospital he is staying at,hyperlinked to its location
        }while($processtable=mysqli_fetch_assoc($fetchospitalperson))
    $message= "Dear"." ".$firstname." ".$lastname.",".PHP_EOL .$messagebody.$hyperlink; 
    if(isset($sendtoperson)){   
        if(mail($to,$header,$message)){
            echo "Sent";
        }
        else{ echo "Not sent";}
    }

    }//end of if person was blooddoner
    // Send Organ donation email if person is organ donner
    $porgandonation="SELECT personprofile.bloodtype,personprofile.bodytype,personprofile.firstname,personprofile.lastname,personprofile.fathername,hospital.hospitalname
        FROM personprofile,hospital,areaname 
        WHERE areaname.id= hospital.area AND personprofile.hospitaladmission= hospital.id AND areaname.area='$city'";
        $fetchorgan=  mysqli_query($link,$porgandonation);
        $processorgan=mysqli_fetch_assoc($fetchorgan);

    if($process['organdoner']=="Yes" && $processorgan['bloodtype']== $process['bloodtype'] && $processorgan['bodytype']== $process['bodytype']  ){ //with same bloodtype,bodytype,intensivecare
        $to=$process['email'];
        $header= "Organ is urgently needed";
        $phquery="SELECT personprofile.firstname,personprofile.lastname,personprofile.fathername,hospital.hospitalname,hospital.geolocation 
        FROM personprofile,hospital,areaname 
        WHERE areaname.id= hospital.area AND personprofile.hospitaladmission= hospital.id AND areaname.area='$city' AND personprofile.admissionreason= 5";
        $fetchospitalperson=  mysqli_query($link,$phquery);
        $processtable=mysqli_fetch_assoc($fetchospitalperson);
       do{
        $messagebody= "Patient Name: ".$processtable['firstname']." ".$processtable['fathername']." ".$processtable['lastname']."  "."Hospital Name:"; 

        //$hyperlink= new DOMDocument();
        //$hyperlink->loadHTML("<html><body><a href='<".$processtable['geolocation']."'>" .$processtable['hospitalname']."</a></body></html>"); 
        $hyperlink= "<html><body><a href='<".$processtable['geolocation']."'>".$processtable['hospitalname']."</a></body></html>";
         //Name of the person that needs the blood transfusion along with hospital he is staying at,hyperlinked to its location
        }while($processtable=mysqli_fetch_assoc($fetchospitalperson))

    $message= "Dear"." ".$firstname." ".$lastname.",".PHP_EOL .$messagebody.$hyperlink.PHP_EOL; 
    if(isset($sendtoperson)){   
        if(mail($to,$header,$message)){
            echo "Sent";
        }
        else{ echo "Not sent";}
    }
} //end of if person was organdonor

1 Answers1

0

first things first, this query here will not necessarily return a unique entry (if that's your intention ) since people can share a first name, a last name and|or a father name! you could use a unique id for unique entries

 $query ="SELECT email,bloodoner,organdoner,bloodtype,bodytype
    FROM personprofile
    WHERE   firstname= '$firstname' AND lastname= '$lastname' AND fathername= '$fathername'";

Also, The way you've used mysqli_fetch_assoc means that if there are multiple rows, it will still only return one row. You could structure it this way:

  while($process=mysqli_fetch_assoc($fetchemail)){
        ----

     }

Finally there is a missing ; on your:

 do { 
           ---------

    } while($processtable=mysqli_fetch_assoc($fetchospitalperson))

it should be:

 do { 
           ---------

    } while($processtable=mysqli_fetch_assoc($fetchospitalperson));
Chogo
  • 311
  • 3
  • 11
  • An alternative for the OP to looping through the result set to grab the results would be mysqli_fetch_all() the OP can specify if they want the result set to be an associative array, a numeric array, or both – SpacePhoenix Apr 28 '18 at 16:52