2016-08-21 130 views
-1

我正在使用PHP和一個SQL服務器,在我解釋得太遠之前,數據庫連接是用require 'databaseconnect.php';執行的代碼是爲了註冊用戶。目前,運行代碼只刷新頁面,並花費數小時嘗試排除故障後,仍然無法找到錯誤。任何幫助將非常感激。我不知道我是否正確編程,這也可能是問題的根源。我的代碼如下:PHP代碼提交按鈕只刷新頁面

 <?php 
session_start(); 
$message = ""; 
require 'databaseconnect.php'; 
if($_POST['register']): 
if(!empty($_POST['username']) && !empty($_POST['password']) && !empty($_POST['confirmPassword']) && !empty($_POST['pin']) && !empty($_POST['preferredName'])): 
    if($_POST['password'] == $_POST['confirmPassword']): 
      $sql = "INSERT INTO Users (Email, Password, FirstName, LastName, Type) VALUES (:email, :password, :firstname, :lastname, :type)"; 
      If($_POST['pin'] == "123456"): 
       $stmt = $conn->prepare($sql); 
       $stmt->bindParam(':email', $_POST['email']); 
       $stmt->bindParam(':password', md5($_POST['password'])); 
       $stmt->bindParam(':firstname', $_POST['firstname']); 
       $stmt->bindParam(':lastname', $_POST['firstname']); 
       $stmt->bindParam(':type', $_POST['AcctType']); 

       if($stmt->execute()): 
        $message = ('<div class="inputlogin alert alert-success" role="alert"><b>You are Registered!</b> You have been registered as a member! <a href = portal.php>Log In!</a></div>');  
       else: 
        $message = ('<div class="inputlogin alert alert-danger" role="alert"><b>There has been an issue...</b> While attempting to register you, there was an error with the server,try again later.</a></div>'); 
       endif; 
      else: 
       $message = ('<div class="inputlogin alert alert-danger alert-dissmissable" role="alert"><b>Oops!</b> Authentication pin not recognized!</div>');  
      endif; 
    else: 
     $message = ('<div class="inputlogin alert alert-danger alert-dissmissable" role="alert"><b>Uh Oh!</b> Passwords Do not Match!</div>'); 

    endif; 

endif; 
endif; 
$conn = null; 
?> 
<html> 
    <head> 
</head> 
    <body> 
     <div class = "container_main"> 

      <a name="top"></a> 

      <br><br> 
      <div class = "mainHeader"> 
      <i class = "fa fa-bars fa-2x mobile_menu" height="100px" widht="100px"></i> 


      </div> 

       <div class = "containerDEF"> 
      <center><img class = "fixed loginImg" src = "CSS/images/TroopLogo.png" alt = "DesignLogo" width = "300" height="300px"></center> 
      <form action = "register.php" method ="POST"> 
       <div class="input-group inputLogIn" id = "FirstName"> 
          <span class="input-group-addon" id="basic-addon1">First Name:</span> 
          <input type="text" class="form-control" placeholder="ex. Clara" aria-describedby="basic-addon1" name="firstname"> 
         </div> 
         <div class="input-group inputLogIn" id = "LastName"> 
          <span class="input-group-addon" id="basic-addon1">Last Name:</span> 
          <input type="text" class="form-control" placeholder="ex. Oswald" aria-describedby="basic-addon1" name="lastname"> 
         </div> 
       <div class="input-group inputLogIn" id = "Email"> 
          <span class="input-group-addon" id="basic-addon1">Email:</span> 
          <input type="text" class="form-control" placeholder="ex. [email protected]" aria-describedby="basic-addon1" name="email"> 
         </div> 
         <div class="input-group inputLogIn" id = "ConfirmEmail"> 
          <span class="input-group-addon" id="basic-addon1">Confirm Email:</span> 
          <input type="text" class="form-control" placeholder="ex. [email protected]" aria-describedby="basic-addon1" name="confirmemail"> 
         </div> 
         <div class="input-group inputLogin" id = "Pass"> 
          <span class="input-group-addon" id="basic-addon1">Password:</span> 
          <input type="password" class="form-control" placeholder="ex. RunYouCleverBoy" aria-describedby="basic-addon1" name="password"> 
         </div> 
         <div class="input-group inputLogin" id = "ConfirmPass"> 
          <span class="input-group-addon" id="basic-addon1">Confirm Password:</span> 
          <input type="password" class="form-control" placeholder="ex. RunYouCleverBoy" aria-describedby="basic-addon1" name="confirmpassword"> 
         </div> 
         <div class="input-group inputLogin" id = "RegistrationPin"> 
          <span class="input-group-addon" id="basic-addon1">Registration Pin:</span> 
          <input type="password" class="form-control" placeholder="******" aria-describedby="basic-addon1" name="pin"> 
         </div> 
         <div class="input-group inputLogin" id = "RegistrationPin"> 
          <span class="input-group-addon" id="basic-addon1">Account Type:</span> 
          <select type = "select" name="AcctType" class = "form-control" > 
        <option value="Scout">Scout</option> 
        <option value="Parent">Parent</option> 
        <option value="Leader">Leader</option> 
       </select> 

         </div> 

         <?php 
          if (!empty($message)): 
           echo ($message); 
         endif; 
         ?> 
        <center><input type = "submit" class = "submitButton" name = "register" value = "Register"></center> 

      </form> 
       <center><p>Just want to login? <a href = "portal.php" class = "lightLink" >Login Here</a>. </p> 
       </center> 
     </div> 
      <br><br> 




      <a href = "#top"><i class = "fa fa-arrow-up up_button fa-2x"></i></a> 
     </div> 




     </div> 
     </div> 
     <script src = "Scripts/Script_Main.js"></script> 

    </body> 
</html> 
+0

我認爲你可以做的是首先顯示錯誤消息,如果有的話,嘗試和調用你的語句傳統的方式。如果(){}然後走你的路... –

+0

你真的有第一個<?php'行縮進,就像你顯示的那樣?這會對'session_start()'造成問題。但由於腳本不使用'$ _SESSION',我不認爲它會導致腳本失敗。 – Barmar

+0

除了未定義的索引,這個'