2011-04-21 171 views
2

我有这个看似简单的一块PHP在我的网站:简单的PHP代码...?

<?php 
$_GET["sid"]; 
if ($sid=="83893") 
    $survey="Survey Name"; 
?> 

这应该使$survey调查“显示名称”,对不对?

在我的网页之后,我有

<h3>Thank You For Participating In The <?php echo $survey; ?></h3> 

如果用户去mypage.php?sid=83893,而不是它呼应调查“显示名称”它不会显示任何东西?为什么是这样?

正如预期的那样,如果我只是把

Thank You For Participating In The <?php echo $_GET["sid"]; ?> 

它写入sid,但为什么不会它输出$survey

+0

您没有任何变量$ sid i你的代码。在你的IF子句中,你应该有$ _GET ['sid'] ==“83893” – yogsma 2011-04-21 03:22:52

回答

6

你永远不会创建变量$sid或分配任何东西。
猜你在寻找$sid = $_GET['sid'];或简单地if ($_GET['sid'] == 83893)

请注意,您应该检查在与isset($_GET['sid'])一起使用前是否确实存在$_GET['sid']。还要注意在开发过程中你应该打开error reporting,它会帮助你解决这个问题。

3

$ sid = $ _GET [“sid”];

然后,它会工作,因为你永远无法定义什么$ SID是

0

你的代码应该是:

<?php 
$sid = $_GET["sid"]; 
if ($sid == "83893") 
    $survey="Survey Name"; 
?> 

再后来,你可以说:

<h3>Thank You For Participating In The <?= $survey ?></h3>