doutan1637 2014-01-07 00:20
浏览 16

为什么不想注册我

for a school assingment i have to make a portfolio. this has to contain a working login and registration system. I got it where it will log people in but only if i manually input data in a database. but now when i try to let people register them self it just keeps giving me the error that the username and email allready exists, what is not true in most cases. i hope u guys can help me with this. here is the code:

<?php
include_once 'db_connect.php';
include_once 'psl-config.php';

$error_msg = "";

if (isset($_POST['username'], $_POST['email'], $_POST['p'])) {
    $username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
    $email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
    $email = filter_var($email, FILTER_VALIDATE_EMAIL);
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $error_msg .= '<p class="error">The email address you entered is not valid!</p>';
    }
    $password = filter_input(INPUT_POST, 'p', FILTER_SANITIZE_STRING);
    if (strlen($password) != 128) {
        $error_msg .= '<p class="error">Invalid password configuration.</p>';
    }
    $query_username = "SELECT id
    FROM members
    Where username == '$username'
    LIMIT 1";
    $available_username = array();
    if ($resultUsername = mysqli_query($mysqli, $query_username)) {
        if (mysqli_num_rows($resultUsername) > 0) {
            $error_msg .= '<p class="error">A user with this username already exists!</p>';
        }
    }
    $query_email = "SELECT id
    FROM members
    Where email == '$email'
    LIMIT 1";
    $available_email = array();
    if ($resultEmail = mysqli_query($mysqli, $query_email)) {
        if (mysqli_num_rows($resultEmail) > 0) {
            $error_msg .= '<p class="error">A user with this username already exists!</p>';
        }
    }
    if (empty($error_msg)) {
        $ipadress = $_SERVER['REMOTE_ADDR'];
        $random_salt = hash('sha512', uniqid(openssl_random_pseudo_bytes(16), TRUE));
        $password = hash('sha512', $password . $random_salt);
        if (!$tableRowEmail = 1) {
            $sqlinsert = "INSERT INTO members (username, email, ipadress, password, salt) VALUES ($username, $email, $ipadress, $password, $random_salt)";
            if (!mysqli_query($mysqli, $sqlinsert)) {
                header('Location: ../error.php?err=Registration failure: INSERT');
            }
        }
        header('Location: ./register_success.php');
    }
}
?>

thanks everyone, made the changes. but now it lets everything through. and it doesn't register anything in my localhost/phpmyadmin. any thoughts?

  • 写回答

3条回答 默认 最新

  • dos49618 2014-01-07 00:22
    关注

    You are using a single equals instead of a double for that line:

    $tableRowUsername == 1
    

    Additionally you should count the number of rows in the SQL result instead of just checking that a row is returned by checking that it is equal to 1.

    评论

报告相同问题?

悬赏问题

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