添加链接时出现语法错误

时间:2013-04-13 15:32:39

标签: php

我尝试修复它,但仍然收到以下Parse错误:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,
 expecting T_STRING or T_VARIABLE or T_NUM_STRING in

这是第13行:

<?php
  if ($fruitdata['fruit'] == "") {
    print "N/A <a href="./add.php?id=<?php print $fruitdata['id']; ?>">Edit</a>"; }
  else {
    print $fruitdata['fruit'];
  }
?>

2 个答案:

答案 0 :(得分:1)

转义双引号并将字符串连接到变量:

<td><?php if ($fruitdata['fruit'] == "") { print "N/A <a href=\"./add.php?id=". $fruitdata['id']."\">Edit</a>"; } else { print $fruitdata['fruit']; } ?>

答案 1 :(得分:0)

多个语法错误。这应该让你直截了当:

<td><?php
if ($fruitdata['fruit'] == "") {
    print 'N/A <a href=./add.php?id='.$fruitdata['id'].'">Edit</a>"';
}else{
    print $fruitdata['fruit'];
}?>