-3

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

1 回答 1

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>';
于 2013-05-06T22:32:27.863 回答