I am working on my PHP to fetch the data from the mysql database. I have got a problem with storing the filename in the array using the values when I have stored both filenames in a database.
Here is what I have stored in the blob:
draft_attachment.rar
draft_attachment - Copy.rar
Here is the code:
$mailbox = $link->prepare("SELECT * FROM draft WHERE id = ?");
$mailbox->execute([$id]);
// set the resulting array to associative
$row = $mailbox->fetch(PDO::FETCH_ASSOC);
$attachments = array();
if($mailbox->rowCount() == 1)
{
$attachment = array();
$draft_to = htmlspecialchars($row['to_email']);
$draft_subject = quoted_printable_decode($row['subject']);
$draft_message = $row['message'];
$attach[] = $row['attachments'];
}
?>
When I try this:
$attach[] = $row['attachments'];
It will store both strings in the array:
Array
{
[0] => draft_attachment.rar
draft_attachment - Copy.rar
}
So I have tried this:
$attachments = array();
$i = 0;
if($mailbox->rowCount() == 1) {
$attachments[$i] = $row['attachments'];
$i++;
}
It wont store the strings separate so I dont know what to do.
Here is what I want to achieve:
Array
{
[0] => draft_attachment.rar
[1] => draft_attachment - Copy.rar
}
Can you please show me an example how I could get both strings to go separate so I could be able to store them in the array using the value?
Thank you.
"'s are valid chars in an email address, htmlspecialchars is going to bork it, XSS is not a thing with to address, instead you should be preventing header injection, which htmlspecialchars wont prevent.