<?php
    $db = new Db();
    $mysqli = Db::$_mysqli;

    if (isset($_POST['name'])) {
        $name = escape($_POST['name']);
        $email = escape($_POST['email']);
        $phone = escape($_POST['phone']);
        $password = escape($_POST['password']);
        $result = array();

        /*check email is unique*/
        $email_num = $db->GetNum("user","email='$email'");

        if ($email_num == 0) {
            /*insert into database*/
            $md5password = md5($password);
            $insert = $db->Insert("user","'','$name','$email','$phone','$md5password'");

            /*success*/
            if ($insert) {
                $result['type'] = "success";
                $result['message'] = "Your are Register";

                /*login the user in*/
                session_start();
                $_SESSION['id'] = mysqli_insert_id($mysqli);

            }else{ /*error*/
                $result['type'] = "error";
                $result['message'] = "Error Please Try again.";
            }

        }else{
            $result['type'] = "error";
            $result['message'] = "Email Already Register <span class='text-bs-primary'>Please Login</span>";
        }

        if(!$error) {
            $sql="select * from user where (name='$name');";
            $res=mysqli_query($conn,$sql);
            if (mysqli_num_rows($res) > 0) {
            // output data of each row
            $row = mysqli_fetch_assoc($res);
            if ($name==$row['name'])
            {
                echo "Name already exists";
            }
            else { //here you need to add else condition
            echo "alright";
        }
        }
    }

        echo json_encode($result);
    }
?>

I think this part will tell you if name exists

 $sql="select * from user where (name='$name');";
            $res=mysqli_query($conn,$sql);
    if (mysqli_num_rows($res) > 0) {
         echo "Name already exists";
    }

thanks, i already resolved the problem in the database, i made my "name" a primary key

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.