php吗?Url字符串不能与变量一起工作


php ? url string not working with variable

我使用PHP根据附加到URL的?来显示不同的消息(使用ècho),如:http://somthing.com/page.php?something=1。我在URL的末尾附加了一个名为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"] . ".";
              }
            }

?>

我在第一行声明了这个变量。没有显示任何消息。我哪里做错了?

    你应该将$_GET['code']设置为$code变量
  • 在使用变量
  • 时应该添加$符号

固定代码:

$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"] . ".";
    }
}

您需要从$_GET

获取数据

像这样:

$code = $GET["code"];