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>
精彩评论