2014-01-21 49 views
0

一個登記表奇異行爲,我在我(的項目)登記表的形式如下網站:(我使用的引導框架):關於PHP

<div id="main-box" class="container"> 
     <div class="row-fluid"> 
      <div id="signup"> 
       <div id="float"></div> 
       <div id="center_signup"> 
        <h3>Registrazione Studente</h3> 
        <?php if (isset($registerError)): ?> 
         <p><?php htmlout($registerError); ?></p> 
        <?php endif; ?> 
        <form action="" method="post" class="form-horizontal"> 
         <div class="form-group"> 
          <label for="nome" class="col-sm-2 control-label">Nome: </label> 
          <div class="col-sm-6"> 
           <input type="text" name="nome" id="nome" class="form-control"> 
          </div> 
         </div> 
         <div class="form-group"> 
          <label for="email" class="col-sm-2 control-label">Email: </label> 
          <div class="col-sm-6"> 
           <input type="text" name="email" id="email" class="form-control"> 
          </div> 
         </div> 
         <div class="form-group"> 
          <label for="password" class="col-sm-2 control-label">Password: </label> 
          <div class="col-sm-6"> 
           <input type="password" name="password" id="password" class="form-control"> 
          </div> 
         </div> 
         <div class="form-group"> 
          <div class="col-sm-offset-2 col-sm-6"> 
           <button type="submit" class="btn btn-success">Submit</button> 
          </div> 
         </div> 
        </form> 
       </div> 
      </div> 
     </div> 

    </div> 

現在形式的數據從控制器的index.php文件,這樣做管理(該register.html.php文件,其中有上面的代碼模板文件):

if (isset($_GET['register'])) 
{ 
    include 'register.html.php'; 

    if (!isset($_POST['email']) or $_POST['email'] == '' or 
    !isset($_POST['password']) or $_POST['password'] == '') 
    { 
     $GLOBALS['registerError'] = 'fill in both fields'; 
     exit(); 
    } 

    $password = md5($_POST['password'] . 'figarodb'); 

    if (databaseContainsUser($_POST['email'], $password)) 
    { 
     $GLOBALS['registerError'] = 'Student already registered.'; 
     exit(); 
    } 

    include $_SERVER['DOCUMENT_ROOT'] . '/figaro/includes/db.inc.php'; 

    // Puts the student in the relevant table 
    try 
    { 
     $sql = 'INSERT INTO studente SET 
        nome = :nome, 
        email = :email, 
        password = :password'; 
     $s = $pdo->prepare($sql); 
     $s->bindValue(':nome', $_POST['nome']); 
     $s->bindValue(':email', $_POST['email']); 
     $s->bindValue(':password', $password); 
     $s->execute(); 
    } 
    catch (PDOException $e) 
    { 
     $error = 'Errore in student registration.'; 
     include $_SERVER['DOCUMENT_ROOT'] . '/figaro/includes/error.html.php'; 
     exit(); 
    } 

    header('Location: .'); 
    exit(); 
} 

這個頭可能會在主頁重定向,但它不這樣做! 如果不是自舉和JavaScript代碼的頁面,我修改了註冊頁面以這樣的方式

<body> 
    <h1>Registration</h1>  
    <form action="" method="post"> 
     <?php if (isset($registerError)): ?> 
      <p><?php echo $registerError; ?></p> 
     <?php endif; ?> 
     <div> 
      <label for="name">Nome completo: <input type="text" name="nome" 
       id="nome"></label> 
     </div> 
     <div> 
      <label for="email">Email: <input type="text" name="email" 
       id="email"></label> 
     </div> 
     <div> 
      <label for="password">Password: <input type="password" 
       name="password" id="password"></label> 
     </div> 
     <div> 
      <input type="submit" value="Invio"> 
     </div> 
    </form> 
</body> 

現在控制器在主頁重定向正確! 我無法解釋這種行爲,任何幫助將不勝感激!謝謝!

回答

0

在你的PHP文件中有記載:

header('Location: .'); 

也許你的Web應用程序在默認情況下的index.html重定向,因爲它是默認的根。

+0

另外index.php是默認的根目錄,如果你打開一個具有index.php文件的文件夾的web應用程序,它將默認打開。 –

+0

此外,我還沒有一個index.html文件... –

+0

這對我來說是一個非常奇怪的錯誤 –