为什么不想要注册我 [英] Why doesn't it want to register me

查看:58
本文介绍了为什么不想要注册我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要进行学校认证,我必须准备一份档案袋.它必须包含一个有效的登录和注册系统.我知道它将在哪里登录用户,但前提是我必须在数据库中手动输入数据.但是现在当我尝试让人们进行自我注册时,它只会不断给我一个错误,提示用户名和电子邮件已经存在,在大多数情况下是不正确的.我希望你们能帮助我.这是代码:

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');
    }
}
?>

感谢大家,做出了改变.但现在它可以让一切顺利通过.并且它没有在我的localhost/phpmyadmin中注册任何内容.有什么想法吗?

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

推荐答案

对于该行,您使用的是单个等于而不是两倍:

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

$tableRowUsername == 1

另外,您应该计算SQL结果中的行数,而不是仅通过检查它是否等于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.

这篇关于为什么不想要注册我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆