douzhanlai4671 2014-10-30 17:14
浏览 59
已采纳

多个“未定义索引”错误[重复]

Okay, really weird... I'm working on a pretty basic registration script, but it returns this:

Notice: Undefined index: username in C:\xampp\htdocs\Zephryte\app\classes\users.class.php on line 42

Notice: Undefined index: email in C:\xampp\htdocs\Zephryte\app\classes\users.class.php on line 46

Notice: Undefined index: email in C:\xampp\htdocs\Zephryte\app\classes\users.class.php on line 50

Notice: Undefined index: emailconfirm in C:\xampp\htdocs\Zephryte\app\classes\users.class.php on line 50

Notice: Undefined index: passwordp in C:\xampp\htdocs\Zephryte\app\classes\users.class.php on line 54

Notice: Undefined index: passwordcomfirm in C:\xampp\htdocs\Zephryte\app\classes\users.class.php on line 54

Notice: Undefined index: username in C:\xampp\htdocs\Zephryte\app\classes\users.class.php on line 58

Notice: Undefined index: passwordp in C:\xampp\htdocs\Zephryte\app\classes\users.class.php on line 62

Notice: Undefined index: passwordp in C:\xampp\htdocs\Zephryte\app\classes\users.class.php on line 66

Notice: Undefined index: username in C:\xampp\htdocs\Zephryte\app\classes\users.class.php on line 70

Which is pretty darn weird, since I named all of the input fields to the corresponding variable:

<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%;" />

And so on... Did I miss anything here?

EDIT:

Since asked for all relevant PHP & HTML code:

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);
    }
</div>
  • 写回答

1条回答 默认 最新

  • dtcrw26206 2014-10-30 17:26
    关注

    Add isset to your 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);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大