Hello,
I’m studying the book PHP & MySQL: Novice To Ninja, 5th Edition.
I am supposed to use this two functions to format output data :
function html($text)
{
return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
}
function htmlout($text)
{
echo html($text);
}
I am using them this way in the template file:
<?php foreach ($authors as $author): ?>
<li>
<form action="" method="post">
<div>
<?php htmlout($author['name']); ?>
<input type="hidden" name="id" value="<?php echo $author['id']; ?>">
<input type="submit" name="action" value="Modify">
<input type="submit" name="action" value="Delete">
</div>
</form>
</li>
<?php endforeach; ?>
And this is the container file:
foreach ($result as $row)
{
$authors[] = array('id' => $row['id'], 'name' => $row=['name']);
}
All this doesn’t work. /var/log/apache2/error.log throws this error:
PHP Warning: htmlspecialchars() expects parameter 1 to be string, array given in /var/www/html/includes/helpers.inc.php on line 4
the file menthioned is the first code I posted.
Thanks for your reply.