Good evening,
I am studying in PHP&Mysql Novice to Ninja, and I am trying to create my first project, but I received this error message:
Warning: htmlspecialchars() expects parameter 1 to be string, array given in /Applications/MAMP/htdocs/manualmanager/includes/helpers.inc.php on line 4
I have create two table:
player
id | number | name | positionid
position
id | name_position
index.php code:
include $_SERVER['DOCUMENT_ROOT'] . '/manualmanager/includes/db.inc.php';
try
{
$result= $pdo->query ('SELECT player.id, number, name, name_position
FROM player INNER JOIN position
ON positionid= position.id');
}
catch (PDOException $e)
{
$error = 'Errore nel recupero dei giocatori dal database' . $e->getMessage();
include 'error.html.php';
exit();
}
foreach ($result as $row)
{
$players[] = array('id'=> $row['id'], 'number' =>$row['number'], 'name'=> $row['name'], 'name_position'=> ['name_position']);
}
include 'player.html.php';
player.html.php code:
<?php include_once $_SERVER['DOCUMENT_ROOT'] . '/manualmanager/includes/helpers.inc.php'; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Player</title>
</head>
<body>
<h1>Player</h1>
<p><a href="?add">Add player</a></p>
<ul>
<?php foreach ($players as $player): ?>
<li>
<form action="" method="post">
<div>
<input type="hidden" name="id" value=" <?php echo $player['id']; ?> ">
<?php htmlout($player['number']); ?>
<?php htmlout($player['name']); ?>
<?php htmlout($player['name_position']); ?>
<input type="submit" name="action" value="Edit">
</div>
</form>
</li>
<?php endforeach; ?>
</ul>
</body>
</html>
helpers.html.php code:
<?php
function html($text)
{
return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
}
function htmlout($text)
{
echo html($text);
}
Could you help me please?
Thank you