簡體   English   中英

在我的 PHP 頁面上點擊提交后,沒有任何反應。 數據應導入我的 php 數據庫

[英]After I hit Submit on my PHP page nothing happens. The data should import into my php database

我創建了這個注冊頁面。 問題是當我輸入信息后單擊提交時沒有任何反應。 它只是刷新同一頁面。 我輸入的信息應該在我點擊提交后導入我的數據庫,並在提交后顯示感謝您注冊的消息。 請幫忙。 我試圖通過在一個頁面上而不是兩個單獨的文件上實現 html 和 php 代碼來將所有內容保持在單頁上。

<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', 'name', 'pswd', 'database')
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 quotes (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 = 'email@email.com';
           $subject = 'New Customer';
           $msg = "$first_name $last_name\n" .
           "Email: $email\n";
           $mail =  mail($to, $subject, $msg, 'From:' . $email);

           if($mail){
           header("Location: https://www.locate.com/blue.php".$first_name);
           exit();
            }
          //Display the user input in an confirmation page  

         echo "<body style='margin-top: 100px; background-color: #f2f0e6;'><p style = 'color: #000000; text-align: center;font-size:300%; font-family:Arial, Helvetica, sans-serif;'><strong>Thanks for signing up!</strong></p><center><p style = 'color: #000000; text-align: center;font-size:200%; font-family:Arial, Helvetica, sans-serif;'>Contact us for any questions
        </p>
        </center>
        </body>";

       }//end of validated data and adding recored to databse. 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/duck.jpg" class="sign-up" alt="Sign Up"></center>
       <br>
       <p>Sign Up to get Discount Code</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>

您要求 $_POST['submit'] 而不是 $_POST['Submit']

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM