ive just done a simple register form where i can check username exists and before i put the username exists in the register works but when i have the username check in it doesnt work can someone check this over for me the script and error log are as follows:

with username check included

<?php require 'Connections/connections.php'; ?>
<?php
    if(isset($_POST['register'])) {

       $username = mysqli_real_escape_string($conn, $_POST['username'];
       $email = mysqli_real_escape_string($conn, $_POST['email'];
       $password = mysqli_real_escape_string($conn, $_POST['password'];

       $storePassword = password_hash($password, PASSWORD_BCRYPT, array('cost' => 10));

       //username check start      
       $username = mysqli_query($conn,"SELECT username FROM users WHERE username='$username'");
       $count = mysqli_num_rows($username);

       if($count!=0){

        die("Username already exists! Please type another username");
       }
       //username check finish

       $sql = mysqli_query($conn,"INSERT INTO users (username, email, password)VALUES('{$username}','{$email}','{$storePassword}')");

       header('Location: login.php');
    }
?>

and error log is

PHP Catchable fatal error:  Object of class mysqli_result could not be converted to string in

if anyone can see whats causing this be much appreciated ty jan x

Recommended Answers

All 4 Replies

ok was querying the die ill sort that hun and ill use the else ty for geting back hun

ok sorry its the way i speak but ty for your sugguestion

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.