如果设置,则将PHP代码放入PHP中

时间:2012-11-10 14:13:03

标签: php html

我在php页面上工作,在同一页面中我已经添加了

<?php if (isset($cpID)) {   echo ' '; }

我已经加入了这两个&#39;&#39;一些代码运行良好,但这个代码有一些小麻烦:

onClick="location.href='waiting.php?picID='.$cpID.''"

它给我语法错误,我不知道如果设置它如何放在PHP中,请帮助我?谢谢Stew

完整代码:

<?php
if (isset($cpID)) {
    echo '</p><button class="btn btn-large btn-block btn-success" onClick="location.href='waiting.php?picID='.$cpID.''"  type="button">Click here to upload this Cover to your Facebook Profile</button></p>';
}
?>

4 个答案:

答案 0 :(得分:0)

你似乎有太多“和”引号的问题。你可以做一些事情。 我确信我能正确理解您的代码,但您可以尝试:

$myEcho = (isset($cpID)) ? "" : "location.href='waiting.php?picID=$cpID'";
echo $myEcho;

我这样做不是现在自己尝试,所以我希望我现在没有通过拼写错误添加语法错误:=)

如果它不起作用,请发布一些有关您所得错误的详细信息。

答案 1 :(得分:0)

问题:

echo '
</p><button class="btn btn-large btn-block btn-success" onClick="location.href='waiting.php?picID='.$cpID.''"  type="button">Click here to upload this Cover to your Facebook Profile</button></p>
';
}

问题是 echo 的单引号被location.href='旁边的单引号关闭。您需要转义单引号。


解决方案:

echo '
</p><button class="btn btn-large btn-block btn-success" onClick="location.href=\'waiting.php?picID='.$cpID.'\'"  type="button">Click here to upload this Cover to your Facebook Profile</button></p>
';

请注意,我已经转义了 \'的单引号

答案 2 :(得分:0)

尝试不将picId设置为var,然后尝试这样做。如果它在表单输入标签中,则为id =“picID”

echo“onclick ='location.href = waiting.php?picID =”+ document.getElementById('picID')。value,true); &LT;&GT;

答案 3 :(得分:0)

我认为第一个问题是PHP标签没有到位。我认为这应该有用

<?php
if (isset($cpID)) {
$cpID = $cpID.' ';
echo '
</p><button class="btn btn-large btn-block btn-success" onClick="location.href='waiting.php?picID='.$cpID.'"  type="button">Click here to upload this Cover to your Facebook Profile</button></p>
';
}
?>