Reputation: 135
So im trying to make it possible for a user to select a file from a list and then delete the file from the server. I know there are alot of safety concerns that I am neglecting here but I really just need to get a basic version of this to work for now. So following up on some other threads here is the linkby which u select a file to delete:
echo '<a href="delete.php?file=ebooks/'.$name.'" onclick="return confirm(\'Are you sure?\')">Delete</a>';
My problem is that where I ad the variable $name to the link it breaks my nesting of quotation marks, escaping them doesn't work since that just renders it as a string "$name" and not a variable. Can anyone please give me or help me to see what the correct way is to write this statement? thanks
Upvotes: 0
Views: 714
Reputation: 2114
Wrap $name in urlencode():
echo '<a href="delete.php?file=ebooks/'.urlencode($name).'" onclick="return confirm(\'Are you sure?\')">Delete</a>';
Upvotes: 1
Reputation: 174977
I like to use Heredoc syntax for complex strings (such as HTML):
echo <<<HTML
<a href="delete.php?file=ebooks/{$name}" onclick="return confirm('Are you sure?')">
Delete
</a>
HTML;
No need to escape quotes, no need to end the string for variables. Simple and looks good.
Upvotes: 0