【问题标题】:POST doesn't pass variable [closed]POST不传递变量[关闭]
【发布时间】:2013-05-06 22:15:55
【问题描述】:

这是我的代码。在我单击按钮转到“playlist.php”文件后,该变量不会像“post”命令中那样被转移。帮忙?

编辑:这是文档中发送变量的代码。

if(empty($name) || empty($email)){
        echo '<h1>Please fill out all fields.</h1>';

    }else{

        $dup = mysql_query("SELECT name FROM sets WHERE name='".$_POST['name']."'");
        if(mysql_num_rows($dup) >0){
            echo '<h1>Username Already Used.</h1>';
        }
        else{

            $sql = mysql_query("INSERT INTO sets VALUES ('','$name','$email')");     
            if($sql){

                 $to = $email; 
                 $email_subject = "You've created a playlist!";
                 $email_body = "Thanks for signing up! ".
                 " Here are the details you used to sign up with:\n Name: $name \n Email: $email"; 

                 $headers = "From: email@email.com"; 
                 $headers .= "Reply-To: email@email.com";

                 mail($to,$email_subject,$email_body,$headers);

                 echo '<form action="playlist.php" method="post">
                    <input type="hidden" name="name" value="<?php echo $name; ?>">
                    <p class="text-center"><button type="submit" class="btn btn-primary btn-large">Visit my Playlist!</button></p>
                 </form>';

            }
            else{
                echo '<h1>Error in Registration.</h1>';
            }
        }
    }

【问题讨论】:

  • 你没有在任何地方检查$_POST['name']
  • 这是发送变量的文档,而不是接收变量的文档。
  • 那么sends 是什么意思?此代码中仅发送邮件
  • 您的html 表单代码是什么样的?

标签: php post curl get


【解决方案1】:

我在您的代码中看到的至少一个错误是这一行:

echo '<form action="playlist.php" method="post">
                    <input type="hidden" name="name" value="<?php echo $name; ?>">
                    <p class="text-center"><button type="submit" class="btn btn-primary btn-large">Visit my Playlist!</button></p>
                 </form>';

&lt;?php echo $name; ?&gt; 不能包含在 echo 语句的字符串文字中。 改用这个:

echo '<form action="playlist.php" method="post">
                    <input type="hidden" name="name" value="' . $name . '">
                    <p class="text-center"><button type="submit" class="btn btn-primary btn-large">Visit my Playlist!</button></p>
                 </form>';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-06
    • 2015-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多