PHP & MySQL Problems?

Hello, I got a problem with my registering system:

<?php

if ($user -> LoggedIn())

{

header('Location: home');

echo 'No access.';

die();

}

if (isset($_POST['reg']))

{

$username = $_POST['username'];

$password = $_POST['password'];

$rpassword = $_POST['rpassword'];

$email = $_POST['email'];

$errors = array();

$checkUsername = $odb -> prepare("SELECT COUNT(*) FROM `users` WHERE `username` = :username");

$checkUsername -> execute(array(':username' => $username));

$countUsername = $checkUsername -> fetchColumn(0);

if ($checkUsername > 0)

{

$errors[] = 'Username is already taken.';

}

if (!ctype_alnum($username) || strlen($username) < 4 || strlen($username) > 15)

{

$errors[] = 'Username Must Be Alphanumberic And 4-15 characters in length';

}

if (!filter_var($email, FILTER_VALIDATE_EMAIL))

{

$errors[] = 'Email is invalid';

}

if (empty($username) || empty($password) || empty($rpassword) || empty($email))

{

$errors[] = 'Please fill in all fields';

}

if ($password != $rpassword)

{

$errors[] = 'Passwords do not match';

}

if (empty($errors))

{

$insertUser = $odb -> prepare("INSERT INTO `users` VALUES(NULL, :username, :password, :email, 0, 0, 0, 0)");

$insertUser -> execute(array(':username' => $username, ':password' => SHA1($password), ':email' => $email));

echo '<div class="alert alert-block alert-success fade in"><button data-dismiss="alert" class="close" type="button">×</button><h4 class="alert-heading">SUCCESS</h4> <p>You have successfully registered, now you can login.</p></div><meta http-equiv="refresh" content="2;url=login">';

}

else

{

echo '<div class="alert alert-block alert-error fade in"><button data-dismiss="alert" class="close" type="button">×</button><h4 class="alert-heading">ERROR</h4> <p>';

foreach($errors as $error)

{

echo '-'.$error.'<br>';

}

echo '</p></div>';

}

}

?>

I always get the error that username is taken, as well as these errors:

Notice: Object of class PDOStatement could not be converted to int in C:\xampp\htdocs\register.php on line 62

Note: Line 62 is: if ($checkUsername > 0)

Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Helpful Social

Copyright © 2024 Q2A.ES - All rights reserved.