Reputation: 5
this is my php code for populating my nav bar through an SQL query. I'm getting the following error:
Parse error: syntax error, unexpected 'index' (T_STRING), expecting ',' or ';' in /home/hj016/public_html/SKSSTW/index1.php on line 102
<?php
$sqlCommand = "SELECT id, linklabel FROM pages ";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while($row = mysqli_fetch_array($query ))
{
echo "<li><a href="index.php?pid=".$row['linklabel'].>".$row['linklabel']."</a></li>";
}
?>
Any help is appreciated.
Upvotes: 0
Views: 146
Reputation: 41595
You have a problem with double quotes, you are closing the echo
string because you are not escaping them.
I recommend you to use simple strings for the echo
function:
echo '<li><a href="index.php?pid="'.$row['linklabel'].'>"'.$row['linklabel'].'"</a></li>';
If you are using double quotes, you can also use {
}
combined with the escaping tag \
:
echo "<li><a href=\"index.php?pid=\"{$row['linklabel']}\">{$row['linklabel']}</a></li>';
Another escaping option opening and closing tags would be:
echo "<li><a href=\"index.php?pid=".$row['linklabel']."\">".$row['linklabel']."</a></li>";
Upvotes: 0
Reputation: 2093
Change
echo "<li><a href="index.php?pid=".$row['linklabel'].>".$row['linklabel']."</a></li>";
to
echo '<li><a href="index.php?pid='.$row['linklabel'].'">'.$row['linklabel'].'</a></li>';
Upvotes: 3