Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple PHP code...? [closed]

Tags:

php

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?

like image 380
Christopher Avatar asked Feb 17 '26 11:02

Christopher


2 Answers

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.

like image 141
deceze Avatar answered Feb 19 '26 00:02

deceze


$sid = $_GET["sid"];

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

like image 41
Colum Avatar answered Feb 19 '26 00:02

Colum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!