POST不传递变量

时间:2013-05-06 22:15:56

标签: php post curl get

这是我的代码。单击按钮转到“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>';
            }
        }
    }

1 个答案:

答案 0 :(得分:2)

我可以在代码中看到至少一个错误:

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>';

<?php echo $name; ?>语句的字符串文字中不能包含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>';