I have this function to read html contents
function patient_file(){
$html= '';
$html .= '<table style="width:100%; padding:0; margin:0; color:rgb(50,50,50); ">
<tr><td style="width:17%"><b style="color:rgb(150,150,150)"> Fullname</b> </td><td> salum said juma</td></tr>
<tr><td><b style="color:rgb(150,150,150)"> Age / sex</b> </td><td> 12 male </td></tr>
<tr><td><b style="color:rgb(150,150,150)"> Address</b> </td><td> kariakoo dsm</td></tr>
<tr><td><b style="color:rgb(150,150,150)"> File number </b> </td><td> mn234</td></tr>
<tr><td><b style="color:rgb(150,150,150)"> kitu package </b> </td><td> scheme name</td></tr>
<tr><td><b style="color:rgb(150,150,150)"> kitu number </b> </td><td> 1234567890</td></tr>
<tr><td><b style="color:rgb(150,150,150)"> kiyutu</b> </td><td> 1919181716151</td></tr>
<tr><td><b style="color:rgb(150,150,150)"> hihi in </b> </td><td> 12-03-2023</td></tr>
<tr><td><b style="color:rgb(150,150,150)"> hihi out</b> </td><td> 12-03-2023 </td></tr>';
$html .= '</table>';
return $html;
}
then after i call the fuction and create json encode
$folio=$_POST['folio'];
$sqlRun = mysqli_query($conn2, "SELECT * FROM m_folio where m_No='$folio'");
$row = mysqli_fetch_assoc($sqlRun);
$row['cardata'] = patient_file();
$json_array[] = $row;
$jasondata = json_encode($json_array);
$payload = '{"entities": ' . $jasondata . '}';
echo $payload;
now the payload generated give error on jsonformatter
this is my output
{"entities": [{"cardata":"rn
Fullname</b> </td> salum said juma</td></tr>rn
Age / sex</b> </td> 12 male </td></tr>rn
Address</b> </td> kariakoo dsm</td></tr>rn
File number </b> </td> mn234</td></tr>rn
kitu package </b> </td> scheme name</td></tr>rn
kitu number </b> </td> 1234567890</td></tr>rn
kiyutu</b> </td> 1919181716151</td></tr>rn
hihi in </b> </td> 12-03-2023</td></tr>rn
hihi out</b> </td> 12-03-2023t</td></tr></table>"}]}
2
Answers
Don’t create
$payload
using string operations. Usejson_encode()
.I’ve also changed the
mysqli
code to use a prepared statement to prevent SQL injection.Remove all line breaks from
$html
inpatient_file()
before returning.This will turn the HTML into one long string which javascript friendly.