开发者

Simple PHP code...? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geogr开发者_如何学Pythonaphic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

I have this seemingly simple piece of PHP in my website:

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

That should make $survey "Survey Name," right?

Later in my page, I have

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

If the user goes to mypage.php?sid=83893, instead of it echoing "Survey Name" it doesn't show anything? Why is this?

As expected, if I simply put

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

It writes the sid, but why won't it output $survey?


You're never creating the variable $sid or assign anything to it.
Guess you're looking for $sid = $_GET['sid']; or simply if ($_GET['sid'] == 83893).

Note that you should check whether $_GET['sid'] actually exists before using it with isset($_GET['sid']). Note also that you should turn on error reporting during development, it would have helped you to catch this problem.


$sid = $_GET["sid"];

Then it will work, as you never define what $sid is


Your answer is

$sid = $_GET['sid'];


Your code should be:

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

then later you can say:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜