57506

Question:
I am using PHP to make different messages display (using ècho
) depending on the ?
attached to the URL, like this: http://somthing.com/page.php?something=1
. I attached a variable called code
to the end of the URL: http://somthing.com/page.php?code=1
.
<?php
$code;
if(code == 1){ echo "Your account has been created.";
} else if(code == 2){
echo "Thank you for your feedback.";
if(isset($_POST["sent"])){
echo "You will receive an email at " . $_POST["youremail"] . ".";
}
}
?>
I declared the variable on line 1. No message is displaying. What am I doing wrong here? <a href="http://sarkelliancreed.comule.com/contact" rel="nofollow">Page the php is on.</a>
Answer1:<ul><li>You should set $_GET['code'] to $code variable</li> <li>You should add $ sign when using a variable</li> </ul><hr />
<strong>Fixed Code:</strong>
$code = isset( $_GET['code'] ) ? $_GET['code'] : 0;
if ( $code == 1 ) {
echo "Your account has been created.";
} else if ( $code == 2 ) {
echo "Thank you for your feedback.";
if ( isset( $_POST["sent"] ) ) {
echo "You will receive an email at " . $_POST["youremail"] . ".";
}
}
Answer2:You need to get data from $_GET
Something like this:
$code = $GET["code"];