-2

So I am getting the following parse error when this file loads:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)

I have tried everything to work out why and I narrowed it down to the

href=\"start.php?id=<?php echo $res['id'] ?>\"

section of the code. I am sure I left out a ' or " but unsure where as it all makes sense to me. Can anyone with a keener eye see where I am going wrong? Thank you.

My code:

<td>

<?php if($res['ndaSent'] == "No") {
echo "<span class=\"buttonTestDisabled\"> Start Test</span>";} 
else {
echo "<a class=\"buttonTest\" href=\"start.php?id=<?php echo $res['id'] ?>\">Start Test</a> ";}
?>

</td>
m7913d
  • 10,244
  • 7
  • 28
  • 56
Antistandard
  • 73
  • 1
  • 7

3 Answers3

1
    echo "<a class=\"buttonTest\" href=\"start.php?id=<?php echo $res['id'] ?>\">Start Test</a> ";
}

Is incorrect, you are closing the PHP code before you are done with the PHP code. And $res['id'] cannot be in your echo like that, you should interpolate the variable correctly in the string. Remove the starting and closing tag inside the echo like this:

echo "<a class=\"buttonTest\" href=\"start.php?id={$res['id']}\">Start Test</a> ";

Please check this awesome guide on how to fix these kind of syntax errors.

Community
  • 1
  • 1
Tom Udding
  • 2,264
  • 3
  • 20
  • 30
1

You cant had snippet in echo use simple string concatenation

<td>

<?php if($res['ndaSent'] == "No") {
echo "<span class=\"buttonTestDisabled\"> Start Test</span>";} 
else {
echo "<a class=\"buttonTest\" href=\"start.php?id=".$res['id']."\">Start Test</a> ";}
?>

</td>
0

Try this

echo "<a class=\"buttonTest\" href=\"start.php?id=" . $res['id'] . " \">Start Test</a> ";}
Ndroid21
  • 400
  • 1
  • 8
  • 19