0

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.

2 Answers 2

3

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>'; 
Sign up to request clarification or add additional context in comments.

Comments

0

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>";     

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.