我正在使用PHP显示不同的消息(使用ècho
),具体取决于附加到网址的?
,如下所示:http://somthing.com/page.php?something=1
。我将名为code
的变量附加到网址的末尾: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"] . ".";
}
}
?>
我在第1行声明了变量。没有显示任何消息。我在这做错了什么? Page the php is on.
答案 0 :(得分:0)
您需要从$ _GET
获取数据这样的事情:
$code = $GET["code"];
答案 1 :(得分:0)
固定代码:
$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"] . ".";
}
}