Reputation: 201
I uploaded a PDF file to a folder called 'forms' on my webserver.
I'm displaying data from my database onto a table, and the forms column I want to link to the file associated within the forms directory.
I've currently got the following;
while ($myrow = mysqli_fetch_array($result)):
$loanid = $myrow["loanid"];
$username = $myrow["username"];
$form = $myrow["form"];
$table = '<tr>';
$table.= '<td>'.$loanid.'</div>';
$table.= '<td>'.$username.'</div>';
$table.= '<td><a href=\"forms/$form\">'.$form.'</a></div>';
echo $table
endwhile;
The table is displaying correctly and the correct file name is displaying in the forms column. However when I click the link it doesn't open the PDF as expected.
When I click the link I would imagine the link should be; www.example.com/website/forms/form.pdf
but im receiving an object not found page and the following link; www.example.com/"forms/$loanform/"
What am I doing wrong?
Upvotes: 0
Views: 57
Reputation: 2642
Try the below code, In your your closing with it should be and you need to use " instead of ' when you are using php varibales in between
<?php
$table = "<table>";
while ($myrow = mysqli_fetch_array($result)):
$loanid = $myrow["loanid"];
$username = $myrow["username"];
$form = $myrow["form"];
$tr = '<tr>';
$tr.= '<td>'.$loanid.'</td>';
$tr.= '<td>'.$username.'</td>';
$tr.= "<td><a href=\"forms/$form\">".$form."</a></td>";
$tr .= "</tr>";
$table .= $tr;
endwhile;
$table .= '</table>';
echo $table
?>
Upvotes: 0
Reputation: 1300
Single quotes does not evaluate variables and you don't need to escape double quotes in them.
Use either
$table.= "<td><a href=\"forms/$form\">".$form."</a></div>";
or
$table.= '<td><a href="forms/' . $form . '">' . $form . '</a></div>';
Upvotes: 1