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 8512583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:19:08+00:00 2026-06-11T04:19:08+00:00

Am not experienced, so appreciate any help. Am looking to build a PHP to

  • 0

Am not experienced, so appreciate any help.

Am looking to build a PHP to confirm that registration of user has a unique email address. If unique, then to add to sql database, and echo out respective value.

This is what I have – the echo value is produced if the email address is duplicate, but the echo value is not produced and the db not updated if it’s unique.

<?php
$email= $_GET["email"];
$firstname = $_GET["firstname"];
$lastname = $_GET["lastname"];

$con = mysql_connect("user","db","pass");
mysql_select_db("db");

$query1 = "SELECT * FROM `db` WHERE `Email` = '$email'";

$result = mysql_query($query1);



if ( mysql_num_rows ($result) == 1 )
{$value="Already registered";

}
else
{
 mysql_query("INSERT INTO db (Email, FirstName, LastName) VALUES ('$email','$firstname','$lastname')");
mysql_close($con);

$value="Confirmed";


}

echo $value;
  • 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-06-11T04:19:09+00:00Added an answer on June 11, 2026 at 4:19 am

    Instead of getting all rows, take only one of them like this. It will save lots of memory.

    $query1 = "SELECT 1 FROM `db` WHERE `Email` = '$email' LIMIT 1";
    

    Then the following line

    if ( mysql_num_rows ($result) == 1 )
    

    will be logically correct. Otherwise if there are 2 or more records in the database, the result is false. With my fix this if will be logical.

    The other solution would be to select the number of the rows, but since the emails are to be unique in the database, there is no point doing something like

    $query1 = "SELECT COUNT(*) FROM `db` WHERE `Email` = '$email'";
    

    However this way, instead of checking the amount of rows in the result, you can check the result without fearing it being empty. But again, since your database’s logic is to have one email only once, there is no point checking how many of them there are since the result will be either 0 or 1 🙂

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

Sidebar

Related Questions

I need help on regex or preg_match because I am not that experienced yet
I am not an experienced iPhone user, so I have a question regarding to
Looking for some help and advice please from Super Guru MySQL/PHP pros who can
I am looking for information, method or code that can help me solve a
Hei there, I'm not experienced at all in C++ as I need to start
I am not much experienced in boost::asio . I've some pretty basic questions. Do
I'm not very experienced in C#, done some small stuff with it, but it's
I'm not an experienced C++ programmer and I'm having problems compiling. I've got a
I'm not very experienced with JavaScript, but this code was similar to what I
I'm not super experienced in writing grammars, but let's say I have a record

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.