Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6369371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:47:48+00:00 2026-05-25T00:47:48+00:00

New programmer- I have created a function to add a user to a database.

  • 0

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?

 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->query ($query);       

            if (!$success || $mysqli -> affected_rows == 0)
            {
                echo "<p> An error occurred: you just are not tough enough!!! </p>";
                return FALSE;
            } 
            $uid = $mysqli -> insert_id;
            return $uid;
            if (!$found_error)
            {
            header("location: homepage.php");
            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:47:48+00:00Added an answer on May 25, 2026 at 12:47 am

    In order to prevent the redirect, you have to inform your front end that there’s been an error.

    Your form will always attempt to “move to the next page” whenever a user clicks “submit.” It will do whatever action is set.

    In that action (which I assume is the next page in the process), you should have the page handle the error – i.e. :

    <?php     //results.php
        if(false === add_member($name, $email, $password)){
           //you may want to write code that sends post data with error type here... 
           header("location:create_user.php");
        }
    ?>
    

    note that using header-redirects is somewhat inelegant, but the best practices of how to handle error is out of scope of this question…

    My point is, you must catch the error on your result page, and have that page handle a failed attempt.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Many years ago I remember a fellow programmer counselling this: new Some::Class; # bad!
I have found this example on StackOverflow: var people = new List<Person> { new
We have 2 new GIS programmer/analyst in our department (new to programming and ArcObjects)
I'm a new Windows programmer and I'm not sure where I should store user
I have a page I created with jQuery, and in this page is a
at my working place (php only) we have a base class for database abstraction.
We have an MSI created by a programmer that left. It has a Installation
I'm a C++ programmer and have a need to set up some UDP communications
I have created an inherited class StorageMedium from a base I called DataTypes. StorageMedium
So I have written a Quaternion based 3D Camera oriented toward new programmers so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.