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

  • SEARCH
  • Home
  • 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 157601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:31:59+00:00 2026-05-11T10:31:59+00:00

I have set my database fields username and email to unquie, when using the

  • 0

I have set my database fields ‘username’ and ’email’ to unquie, when using the code below this only works if the ‘username’ already exists, an error is then echoed. If they email exists the user gets a mysql duplicate error, when the same error as above should be shown.

<?php  require_once ( 'connection.php' );  $username=$_POST['username'];  $password=md5($_POST['password']); $email=($_POST['email']); $ip=$_SERVER['REMOTE_ADDR']; session_start();  $query = 'INSERT INTO users (username, password, email, rank, ip, active) VALUES     ('$username','$password', '$email', '1', '$ip', '0')';  $sql = 'SELECT username AND email FROM users WHERE username = '$username' AND  email     = '$email'' ; $result=mysql_query($sql); $count=mysql_num_rows($result); $row = mysql_fetch_array($result);  if ( $count== 0 ) { if (!mysql_query($query)) {  die('Error: ' . mysql_error()); }   echo 'You are signed up, please follow the link on your email to active your        account.'; } else  {   echo 'Username or Email already exists'.'<br><a href=\'sign_up.php\'>Try    Again</a></br>';  }   ? 

Thanks

  • 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. 2026-05-11T10:32:00+00:00Added an answer on May 11, 2026 at 10:32 am

    Try switching

    WHERE username = '$username' AND  email     = '$email'' 

    to

    WHERE username = '$username' OR email     = '$email'' 

    Edit: I’m trying to guess what you’re trying to do here. From your description, it seems you want either the username or the email to be unique and you have two separate unique indexes on those columns. Your code checks for the combination of username and email to be unique.

    Edit 2: Also, I think you might want to look into the concepts of SQL Injection and Concurrency.

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

Sidebar

Related Questions

In a database prototype, I have a set of fields (like name, description, status)
I am using UTF-8 in my HTML and have set my database table's collation
I have a legacy database set with NLS_LANG set to IW8ISO8859P8. This I cannot
You often see database fields set to have a magnitude of 255 characters, what
I have a SQL database that has a table with a field set to
I have set up the following: Database class ($db) Pagination class ($paginator) I am
i have set up an SQLite database. it seems that when i run a
Suppose the following: I have a database set up on database.mywebsite.com , which resolves
Ok, here is my dilemma I have a database set up with about 5
I have a mysql database set as utf-8, and csv data set as utf-8,

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.