【问题标题】:When push the Submit button it shows the same page, but blank. I want it to load the thank you page当按下提交按钮时,它显示相同的页面,但为空白。我希望它加载感谢页面
【发布时间】:2020-02-28 16:32:20
【问题描述】:

由于某种原因,当我点击提交按钮时,它再次加载相同的 url,页面为空白。当我单击提交按钮时,它应该加载一个包含一般信息的新感谢页面。如果您查看我的位置标题 url,它会显示应该加载的谢谢 url,但这就像我的页面完全忽略加载感谢页面并且只加载相同的注册页面,但它显示完全空白。

<html>
 <body>
   <?php       
    $output_form = true; //declare a FLAG we can use to test whether or not to show form

    $first_name = NULL;
    $last_name = NULL;
    $email = NULL;

    if (isset($_POST['submit']) ) { //conditional processing based on whether or not the user has submitted.

    $dbc = mysqli_connect('localhost', 'db', 'psw', 'db_folder')
    or die('Error connecting to MySQL server.');

    $first_name = mysqli_real_escape_string($dbc, trim($_POST['firstname']));
    $last_name = mysqli_real_escape_string($dbc, trim($_POST['lastname']));
    $email = mysqli_real_escape_string($dbc, trim($_POST['email']));

    $output_form = false; // will only change to TRUE based on validation

 //Validate all form fields 
    if (empty($first_name)) {

    echo "WAIT - The First Name field is blank <br />";
    $output_form = true; // will print form.
    }

    if (empty($last_name)) {

    echo "WAIT - The Last Name field is blank <br />";
    $output_form = true; // will print form.
    }

    if (empty($email)) {

    echo "WAIT - The Email field is blank <br />";
    $output_form = true; // will print form.
    }

    if ((!empty($first_name)) && (!empty($last_name)) && (!empty($email))) {
 //End of form validation


 //This section establishes a connection to the mysqli database, and if it fails display error message

    $query = "INSERT INTO email_list (first_name, last_name, email) " .
    "VALUES ('$first_name', '$last_name', '$email')";

    $result = mysqli_query($dbc, $query)
    or die('Error querying database.');

    mysqli_close($dbc);

    $to = 'newsletter@test.com';
    $subject = 'New Signup';
    $msg = "$first_name $last_name\n" .
    "Email: $email\n";
    $mail =  mail($to, $subject, $msg, 'From:' . $email);

    if($mail){
    header("Location: http://www.example.com/thanks.php?fn=".$first_name);
    exit();
    }

   }//end of validated data and adding recored to database. Closes the code to send the form.

  } //end of isset condition. This closes the isset and tells us if the form was submitted.

  else { //if the form has never been submitted, then show it anyway
  $output_form = true;
}

  if ( $output_form ) { //we will only show the form if the user has error OR not submitted.

?>
<div id="box">
    <center><img src="../../images/signup/image.png" class="sign-up" alt="Sign Up">   </center>
    <br>
    <p>Sign Up</p><br>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?> ">
        <div> 
            <label for="firstname">First name:</label>
            <input type="text" id="firstname" name="firstname" size="37" maxlength="37" value="<?php echo $first_name; ?>" />
        </div>
        <div>
            <label for="lastname">Last name:</label>
            <input type="text" id="lastname" name="lastname" size="37" maxlength="37" value="<?php echo $last_name; ?>" />
        </div>
        <div>
            <label for="email">Email:</label>
            <input type="text" id="email" name="email" size="37" maxlength="37" value="<?php echo $email; ?>" />
        </div>
            <div id="submit">
            <input type="submit" name="submit" value="Submit" />
            </div></center>
    </form>
  </div>
 <?php  
 }
 ?>
 </body>
</html>

【问题讨论】:

标签: php button submit


【解决方案1】:
<html>
   <Body>

需要在header("location...");之后。

试着把它放在&lt;div id="box"&gt;之前。

【讨论】:

  • 我尝试按照你说的添加 和 标签,但仍然得到相同的结果。
  • 也许 if($mail) 返回 FALSE
  • 尝试在if($mail)关闭}之后添加else{ echo "false"; }
猜你喜欢
  • 2014-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-12
  • 2022-01-26
  • 1970-01-01
  • 2015-12-23
相关资源
最近更新 更多