So I am trying to create an login system on my localhost server with xampp and but my sql query is not running [duplicate]

早过忘川 提交于 2020-04-07 10:44:15

问题


I am trying to make a loginsystem with localhost server in xampp and phpmyadmin but the mysqli statement is somehow showing error. Ps I am new to this, So if this is some silly mistake ,sorry.

When i enter the details for registeration form The sql error header beacuse the mysqli statement didnt run properly

Here is the code of my signup.php file

<?php
if(isset($_POST['register'])){
include_once 'dph.php';


$first=$_POST['first'];
$last=$_POST['last'];
$username= $_POST['username'];
$password= $_POST['password'];
$email= $_POST['email'];

if(empty($username)||empty($password)||empty($email)||empty($first)||empty($last)){
    header("Location:../register.php?signup=emptyfields");
    exit();
}
elseif(!filter_var($email,FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9]*$/",$username)){
    header("Location:../register.php?signup=invalid&usernameor&email");
}
elseif(!filter_var($email,FILTER_VALIDATE_EMAIL))
    {
        header("Location:../register.php?signup=invalidemail&username=",$username);
        exit();
    }
elseif(!preg_match("/^[a-zA-Z0-9]*$/",$username)){
            header("Location:../register.php?signup=invalidusername&email=",$email);
            exit();
    }
else{

    $sql = "SELECT userUid FROM users WHERE userUid=?";
    $stmt = mysqli_stmt_init($conn);
    if(!mysqli_stmt_prepare($stmt, $sql)){

        header("Location:../register.php?signup=sqlerror1");    //right here this part
        exit();  
            }
    else{
        mysqli_stmt_bind_param($stmt,"s",$username);
        mysqli_stmt_execute($stmt);
        mysqli_stmt_store_result($stmt);
        $resultCheck=mysqli_stmt_num_rows($stmt);
        if($resultCheck >0){
            header("Location:../register.php?signup=usernametaken&email=",$email);
        exit(); 
        }   
    else{     
        $sql="INSERT INTO users(userFirst,userLast,userEmail,userUid,userPwd) VALUES(?,?,?,?,?)";
        $stmt =mysqli_stmt_init($conn);
        if(!mysqli_stmt_prepare($stmt,$sql)){

        header("Location:../register.php?signup=sqlerror2");
        exit();  
            }
        else{
            $hashedPwd = password_hash($password,PASSWORD_DEFAULT);
        mysqli_stmt_bind_param($stmt,"sssss",$first,$last,$email,$username,$hashedPwd);
        mysqli_stmt_execute($stmt);
          header("Location:../register.php?signup=success");
        exit();  
        }
    }
}
mysqli_stmt_close($stmt);
mysqli_close($conn);

}
}
else{
header("Location: ../signup.php");
exit();
}

?>

来源:https://stackoverflow.com/questions/60683422/so-i-am-trying-to-create-an-login-system-on-my-localhost-server-with-xampp-and-b

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!