Click here to Skip to main content
15,888,037 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm making a PHP login system through a tutorial, but I got an error I don't know how to solve it..
In my url i get a sqlerror.
I got a dbhandler in another file but i'm sure that is not the issue because it's working in another file.
I checked for syntax errors and that is not the issue..
Can somebody help me?
This is my code:
PHP
<pre><?php
if (isset($_POST['signup-submit'])) {

  require 'dbh.inc.php';

  $username = $_POST['uid'];
  $email = $_POST['mail'];
  $password = $_POST['pwd'];
  $passwordrepeat = $_POST['pwd-repeat'];

if (empty($username) || empty($email) || empty($password) || empty($passwordrepeat)) {
    header("Location: ../signup.php?error=emptyfields&uid=".$username."&mail=".$email);
    exit();
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9]*$/", $username)) {
    header("Location: ../signup.php?error=invalidmailuid=");
    exit();
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    header("Location: ../signup.php?error=invalidmail&uid=".$username);
    exit();
} elseif (!preg_match("/^[a-zA-Z0-9]*$/", $username)) {
    header("Location: ../signup.php?error=invaliduid&mail=".$email);
    exit();
} elseif ($password !== $passwordrepeat) {
    header("Location: ../signup.php?error=passwordcheck&uid=".$username."&mail=".$email);
    exit();
} else {

  $sql = "SELECT uidUsers FROM users uidUsers=?";
  $stmt = mysqli_stmt_init($conn);
  if (!mysqli_stmt_prepare($stmt, $sql)) {
    header("Location: ../signup.php?error=sqlerror");
    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: ../signup.php?error=usertaken&mail=".$email);
    exit();
} else {

  $sql = "INSERT INTO users (uidUsers, mailusers, pwdUsers) VALUES (?, ?, ?)";
  $stmt = mysqli_stmt_init($conn);
  if (!mysqli_stmt_prepare($stmt, $sql)) {
    header("Location: ../signup.php?error=sqlerror");
    exit();
} else {
  $hashedPwd = password_hash($password, PASSWORD_DEFAULT);

  mysqli_stmt_bind_param($stmt, "sss", $username, $email, $hashedPwd);
  mysqli_stmt_execute($stmt);
  header("Location: ../signup.php?signup=success");
  exit();
}

}

}

}
 mysqli_stmt_close($stmt);
 mysqli_close($conn);

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


Thanks Sam

What I have tried:

I tried to follow the tutorial for a simple login system from mmtuts on yt.
Posted
Updated 6-Jul-20 2:24am
v2
Comments
Richard MacCutchan 6-Jul-20 9:17am    
What is the error? At a guess your SELECT statement is missing the word "WHERE" before the ending condition. As OriginalGriff suggests, you should throw this code in the bin and study some proper tutorials. Those at W3Schools Online Web Tutorials[^] are all very easy to follow.

1 solution

Quote:
I tried to follow the tutorial for a simple login system from mmtuts on yt.

So go back there and ask him - he will know more about his code than we will.

But frankly, if that's the quality of his code at it's best, I'd throw it in the bin and move on ...
 
Share this answer
 
Comments
Sam Vorst 6-Jul-20 8:40am    
But maybe you see the error, i can't ask it him because he don't gonna answer me.
Sam Vorst 6-Jul-20 10:16am    
Allright why is the code so bad?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900