I am confused why you keep moving the code around into different order. This is how it should be.
Set up your database connection (Not 100% sure, but, I think that is what the dog.php is for.
(Normally we would call that config.php or db_connect.php, something that makes you think of DB set up.)
Next, get the form reference number which you did.
Now, load all of the fields of data which is done with a mysqli_fetch_assoc() function not a fetch_fields() function. You moved this part down into the PDF code, too. WHY? It needs to be before you create your PDF.
Then, load the template of the form. For some odd reason you moved it into the PDF code section.
After loading the template which is housed in the $new_form variable, you then replace the code words in the template with the live fields. For some reason you moved this section down into the PDF code section.
Lastly, with the template now created and all of the keywords replaced with live data, you use the PDF library to create the PDF for you. And, of course send it to the browser so the user can review the finished form.
So, please rewrite the order of your code and repost the new version and it should work.
Oh, also, the error you showed us is because you used OOP style of coding the first part of your query and then when you get the data, you did not use OOP. (Object Orientated Programming) So, your query would need to be changed. Something like this:
$db->query("SELECT name, data FROM thetitl1_livesite754.form_data WHERE form_id IN(SELECT id FROM thetitl1_livesite754.forms WHERE reference_code ='.$refcode.')");
//Replaces form_fields in html temp with "data"
if ($db) {
//below is the line referenced in error message above
while ($row = $db->fetch_array(MYSQLI_ASSOC)) {
$new_form = str_replace($row["name"], $row["data"], $new_form);
}
}
Notice the slight difference in the $row= part. The two types of programming these are called “Object Orientated Programming” and “Procedural Programming”. They are quite different. You started the DB connection and query using OOP ( $db->etc ) and created the $row’s using fetch($DB) which is the procedural version. Hope you understand the difference.
Go to it. Rewrite using my notes and repost the code when done. That should finish this project up for you I think! Good luck…