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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:23:41+00:00 2026-06-10T06:23:41+00:00

I don’t know where I am going wrong in else if logic… I want

  • 0

I don’t know where I am going wrong in else if logic…
I want to validate this signup script in 3 steps:

1st: check if any field is empty, in which case include errorreg.php and register.php.

2nd: If email already exists include register.php.

3rd: If all goes well insert data to the database.

<?php
    $address =$_POST["add"];
    $password =$_POST["pw"];
    $firstname =$_POST["fname"];
    $lastname =$_POST["lname"];
    $email =$_POST["email"];
    $contact =$_POST["cno"];


    $con=mysql_connect("localhost","root","");
    mysql_select_db("bookstore");
    $q2=mysql_query("select * from customer where email='$email'");
    $b=mysql_fetch_row($q2);
    $em=$b[0];

   if($password != $_POST['pwr'] || !$_POST['email'] || !$_POST["cno"] || !$_POST["fname"] || !$_POST["lname"] || !$_POST["add"])
    {
        include 'errorreg.php';
        include 'register.php';
    }

    else if($em==$email)
    {
        echo 'email already present try another';
        include 'register.php';
    }
    else
    {
        $con=mysql_connect("localhost","root","");
        mysql_select_db("bookstore");
        $q1=mysql_query("insert into customer values('$email','$password','$firstname','$lastname','$address',$contact)");

        echo 'query completed';
        $q2=mysql_query("select * from customer where email='$email'");
        $a=mysql_fetch_row($q2);
        print "<table border =2px solid red> <tr><th>id </th></tr>";
        print "<td>$a[0]</td>";

        print "</table>";
        include 'sucessreg.php';
        echo " <a href='newhome.php'>goto homepage</a>";
    }

?>
  • 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-10T06:23:43+00:00Added an answer on June 10, 2026 at 6:23 am

    There’s a lot to correct here, but to your specific concern, that the “loop” doesn’t go on to the second and third “steps”, that’s because you’re thinking about this wrong. In an if/else if/else code block, only one of the blocks is executed at a time, the others are not. For instance, if a user submitted a number, we could tell them it was even or odd with the following:

    if($_GET['number'] % 2 == 0){
      echo "That's even!";
    } else {
      echo "That's odd!";
    }
    

    You are attempting to do one check, then another, then a third. In this case, you want to nest your conditionals (if statements) rather than have them come one after another, like so:

    if(/* first, basic sanity check*/) {
      if(/* second, more complex check */) {
        if(/* final check */) {
          // Database update
        } else {
          // Failed final check
        }
      } else {
        // Failed second check
      }
    } else {
      // Failed basic check
    }
    

    Some other comments on your code:

    1. Pay attention to formatting – laying out your code in consistent and visually clear patterns will help make it easier to see when you make a mistake.
    2. Use isset($_POST['variable']) before using $_POST['variable'], otherwise you’ll get errors. One idea is to use lines like: $address = isset($_POST['address']) ? $_POST["add"] : ''; – if you don’t know that notation, it lets you set $address to either the value from the $_POST array or '' if it’s not set.
    3. Use the variables you created, like $email and $contact, rather than re-calling the $_POST variables – they’re clearer, shorter variable names.
    4. Use the better MySQLi library, rather than the MySQL library.
    5. Create one connection ($con = ...) to your database at the beginning of your script, and don’t create a second one later on, like you do here.
    6. Explicitly specify which connection your queries are running against – you say $q2=mysql_query("SELECT ...") but you should also pass the connection you’ve constructed,
      $q2=mysql_query("SELECT ...",$con).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know why, but this code worked for me a month ago... maybe
Don't know if I worded the question right, but basically what I want to
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know if this has been asked before, so point me to another question
Don't know if anyone can help me with this or if it's even possible.
Don't know whats exactly going on, but it's definitely killing my time for nothing.
I don't know: if this works. if it's a good idea. what it is
I don't know if this question is trivial or not. But after a couple
Don't know why this doesn't work. I can't do implicit animation for a newly
Don't know what's wrong here, when I run the application it says Specified method

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.