2014-10-30 71 views
0

好吧,確實很奇怪......我工作的一個非常基本的註冊腳本,但它返回:多「未定義指數」錯誤

公告:未定義的索引:在 Ç用戶名:\ XAMPP \ htdocs \ Zephryte \ app \ classes \ users.class.php on line 42

注意:未定義的索引:電子郵件地址 C:\ xampp \ htdocs \ Zephryte \ app \ classes \ users.class.php在行46

說明:未定義索引:電子郵件地址 C:\ xampp \ htdocs \ Zephryte \ app \ classe小號\ users.class.php上線50

說明:未定義指數:emailconfirm在 C:\ XAMPP \ htdocs中\ Zephryte \應用\類\上線50 users.class.php

說明:未定義指數:passwordp在 C:\ XAMPP \ htdocs中\ Zephryte \應用\類\上線users.class.php 54

說明:未定義指數:passwordcomfirm在 C:\ XAMPP \ htdocs中\ Zephryte \應用\類\ users.class.php 54行

注意:未定義的索引:用戶名在 C:\ XAMPP \ htdocs中\ Zephryte \應用\類\上線users.class.php 58

說明:未定義指數:passwordp在 C:\ XAMPP \ htdocs中\ Zephryte \應用\類\上線users.class.php 62

說明:未定義指數:passwordp在 C:\ XAMPP \ htdocs中\ Zephryte \應用\類\上線users.class.php 66

說明:未定義指數:用戶名在 C:\ XAMPP \ htdocs \ Zephryte \ app \ classes \ users.class.php on line 70

這是相當不錯的怪異,因爲我命名所有輸入字段對應的變量:

<input type="text" name="username" size="45" placeholder="Username..." class="input" style="width: 98%;" /> 
<input type="text" name="email" size="45" placeholder="E-Mailadres..." class="input" style="width: 98%;" /> 

等等......難道我在這裏錯過了什麼?

編輯:

由於要求所有相關的PHP & HTML代碼:

HTML:

<form action="index.php?p=register" method="post" autocomplete="off"> 
     <table align="center" cellpadding="8" style="width: 100%;"> 
    <tr> 
    <td style="width: 100%;"> 
    <input type="text" name="username" size="45" placeholder="Username..." class="input" style="width: 98%;" /> 
    </td> 
    </tr> 
    <tr> 
    <td style="width: 100%;"> 
    <input type="text" name="email" size="45" placeholder="E-Mailadres..." class="input" style="width: 98%;" /> 
    </td> 
    </tr> 
    <tr> 
    <td style="width: 100%;"> 
    <input type="text" name="emailconfirm" size="45" placeholder="E-Mailadres bevestigen..." class="input" style="width: 98%;" /> 
    </td> 
    </tr> 
    <tr> 
    </tr> 
    <tr> 
    <td style="width: 100%;"> 
    <input type="password" name="passwordp" size="45" placeholder="Wachtwoord..." class="input" style="width: 98%;" /> 
    </td> 
    </tr> 
    <tr> 
    </tr> 
    <tr> 
    <td width="100%"> 
    <input type="password" name="passwordconfirm" size="45" placeholder="Wachtwoord bevestigen..." class="input" style="width: 98%;" /> 
    </td> 
    </tr> 
    <tr> 
    <td style="width: 100%;"> 
    <input type="text" name="skype" size="45" placeholder="Skype..." class="input" style="width: 98%;" /> 
    </td> 
    </tr> 
    <tr> 
    </tr> 
    <td width="30%"> 
    <input type="submit" name="register" value="Registreren" class="button small orange" style="width: 100%;"> 
    </td> 
    </table> 
    </form> 

PHP:

public function register() 
    { 
     $query = $this->db->conn->prepare('INSERT INTO ht_users VALUES "", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?'); //22 
     $errors = array(); 
     if (strlen($_POST['username']) < 3) 
     { 
      $errors[] = "Je gebruikersnaam is niet geldig"; 
     } 
     if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) 
     { 
      $errors[] = "Je emailadres is niet geldig"; 
     } 
     if ($_POST['email'] !== $_POST['emailconfirm']) 
     { 
      $errors[] = 'Je emailadressen zijn niet \'t zelfde!'; 
     } 
     if ($_POST['passwordp'] !== $_POST['passwordcomfirm']) 
     { 
      $errors[] = 'Je wachtwoorden zijn niet \'t zelfde'; 
     } 
     if (!ctype_graph($_POST['username'])) 
     { 
      $errors[] = 'Je gebruikersnaam bezit ongeldige tekens!'; 
     } 
     if (strlen($_POST['passwordp']) < 6) 
     { 
      $errors[] = 'Je wachtwoord moet op z\'n minst 6 tekens lang zijn'; 
     } 
     if (strlen($_POST['passwordp']) > 20) 
     { 
      $errors[] = 'Je wachtwoord mag maximaal 20 tekens bevatten!'; 
     } 
     if ($this->checkUsername($_POST['username'])) 
     { 
      $errors[] = 'Oeps! Er bestaat al een account op deze Habbonaam!<br>Ben je misschien je <a href="?p=lostpass">wachtwoord vergeten</a>?'; 
     } 
     if ($this->checkEmail($_POST['email'])) 
     { 
      $errors[] = 'Oeps! Er bestaat al een account op dit emailadres!<br>Ben je misschien je <a href="?p=lostpass">wachtwoord vergeten</a>?'; 
     } 
     if (count($errors) > 0) 
     { 
      echo 'FUCK'; 
      //return $errors; 
      exit(); 
     } 
     $password = md5($_POST['passwordp']); 
     $data = date('d-M-Y'); 
     $ipAddress = $_SERVER['REMOTE_ADDR']; 
     if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) { 
      $ipAddress = array_pop(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])); 
     } 

     $query->bind_param('ssssssssssssssssssssss', $data, $username, $password, NULL, $email, $this->generateCode($username), $ipAddress, $ipAddress, $data, $data, 1, NULL, NULL, 0, 0, 1, 1, 0, $skype, 0, 0, NULL); 
     $query->execute(); 
     $query->close(); 
     $this->login($username, $passwordp); 
    } 
+0

檢查提交前是否設置了它們。 – Mihai 2014-10-30 17:16:36

+0

在訪問 – MH2K9 2014-10-30 17:17:35

+0

之前,還可以使用'isset()'請包含所有相關的HTML和PHP代碼,包括您的'

'標籤和引發錯誤的PHP代碼。 – showdev 2014-10-30 17:17:45

回答

0

添加isset到PHP:

public function register() 
{ 
    $query = $this->db->conn->prepare('INSERT INTO ht_users VALUES "", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?'); //22 
    $errors = array(); 
    if (!isset($_POST['username']) || strlen($_POST['username']) < 3) 
    { 
     $errors[] = "Je gebruikersnaam is niet geldig"; 
    } 
    if (!isset($_POST['email']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) 
    { 
     $errors[] = "Je emailadres is niet geldig"; 
    } 
    if (!isset($_POST['email']) || !isset($_POST['emailconfirm']) || $_POST['email'] !== $_POST['emailconfirm']) 
    { 
     $errors[] = 'Je emailadressen zijn niet \'t zelfde!'; 
    } 
    if (!isset($_POST['passwordp']) || !isset($_POST['passwordcomfirm']) || $_POST['passwordp'] !== $_POST['passwordcomfirm']) 
    { 
     $errors[] = 'Je wachtwoorden zijn niet \'t zelfde'; 
    } 
    if (!isset($_POST['username']) || !ctype_graph($_POST['username'])) 
    { 
     $errors[] = 'Je gebruikersnaam bezit ongeldige tekens!'; 
    } 
    if (!isset($_POST['passwordp']) || strlen($_POST['passwordp']) < 6) 
    { 
     $errors[] = 'Je wachtwoord moet op z\'n minst 6 tekens lang zijn'; 
    } 
    if (!isset($_POST['passwordp']) || strlen($_POST['passwordp']) > 20) 
    { 
     $errors[] = 'Je wachtwoord mag maximaal 20 tekens bevatten!'; 
    } 
    if (!isset($_POST['username']) || $this->checkUsername($_POST['username'])) 
    { 
     $errors[] = 'Oeps! Er bestaat al een account op deze Habbonaam!<br>Ben je misschien je <a href="?p=lostpass">wachtwoord vergeten</a>?'; 
    } 
    if (!isset($_POST['email']) || $this->checkEmail($_POST['email'])) 
    { 
     $errors[] = 'Oeps! Er bestaat al een account op dit emailadres!<br>Ben je misschien je <a href="?p=lostpass">wachtwoord vergeten</a>?'; 
    } 
    if (count($errors) > 0) 
    { 
     echo 'NEUKEN'; 
     //return $errors; 
     exit(); 
    } 
    $password = md5($_POST['passwordp']); 
    $data = date('d-M-Y'); 
    $ipAddress = $_SERVER['REMOTE_ADDR']; 
    if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) { 
     $ipAddress = array_pop(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])); 
    } 

    $query->bind_param('ssssssssssssssssssssss', $data, $username, $password, NULL, $email, $this->generateCode($username), $ipAddress, $ipAddress, $data, $data, 1, NULL, NULL, 0, 0, 1, 1, 0, $skype, 0, 0, NULL); 
    $query->execute(); 
    $query->close(); 
    $this->login($username, $passwordp); 
}