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


        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

1 Year
Discussion Span
Last Post by janicemurby

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.