how to let user know that name already exists
<p>New programmer- I have created a function to add a user to a database. This function is found in class USER. I have set up mysql to have user_name as a unique key. If a user tries to enter a name that already exists it is not entered into the mysql database but my form says ok its been submitted and just moves to the next page. I want to let the user know that the name already exists and create an error on the registration form. Is there a way to append that to this function?</p>

<pre><code> function add_member($name, $email, $password)
        {
            global $mysqli;

            $query = "INSERT INTO members
                      SET 
                      user_name = '".addslashes($name)."',
                      user_email = '".addslashes($email)."',
                      password = '". md5($password) ."'";

            $success = $mysqli-&gt;query ($query);       

            if (!$success || $mysqli -&gt; affected_rows == 0)
            {
                echo "&lt;p&gt; An error occurred: you just are not tough enough!!! &lt;/p&gt;";
                return FALSE;
            } 
            $uid = $mysqli -&gt; insert_id;
            return $uid;
            if (!$found_error)
            {
            header("location: homepage.php");
            }
</code></pre>
