echo语句校正中的变量

时间:2013-06-13 14:23:35

标签: php variables echo

下面的代码解析好但是没有用,我已经尝试了几个版本的编写方式和我能够获得的最好的是重定向工作,但PHP变量没有放在传递的url中。当代码有很多组合时,我很难弄清楚单引号与双引号何时/何处需要/使用。在这种情况下,使用AJAX或JQUERY等等不是我的选择,所以尽管可以采用不同的方法,但请坚持使用HTML / PHP代码。提前谢谢。

echo '<input name="Edit" type="button" value="Edit Product" onclick="location.href=\"add-firearm.php?eval=edit&eitem=.\"$row[SKU]\" " />';

2 个答案:

答案 0 :(得分:2)

原样,您的echo会产生:

<input name="Edit" type="button" value="Edit Product" onclick="location.href=\"add-firearm.php?eval=edit&eitem=.\"$row['SKU']\" " />

你想要

<input name="Edit" type="button" value="Edit Product" onclick="location.href='add-firearm.php?eval=edit&eitem=$row['SKU']'" />

所以你的echo应该是这样的:

echo '<input name="Edit" type="button" value="Edit Product" onclick="location.href=\'add-firearm.php?eval=edit&eitem=' . $row['SKU'] . '\'" />';

答案 1 :(得分:0)

echo "<input name='Edit' type='button' value='Edit Product' onclick='location.href='add-firearm.php?eval=edit&eitem=".$row[SKU]."' />"

你忘记了'。'。