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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:57:12+00:00 2026-06-15T04:57:12+00:00

I am new to PHP scripting and come from Java background. Here is a

  • 0

I am new to PHP scripting and come from Java background. Here is a trivial thing which has turned into a brainteaser for me as of now. So here is the problem, I assigned a variable some value and when try to use that value inside if/else statement that variable actually doesn’t posses the previous assigned value to it. Here is the code:-

<?php
    session_start();

    $email = $_POST["Email"];   
    $password = $_POST["Password"];

    $db_username="root";
    $db_password="root";
    $database="mydb";
    $localhost = "mysql";

    $con = mysql_connect($localhost,$db_username,$db_password);
    mysql_select_db($database,$con) or die( "Unable to select database");

    $query = "select * from photobook.users where email ='$email' and password ='$password';" ;

    $result = mysql_query($query);

    $num=mysql_num_rows($result);

    if($num == 1){
        while($row = mysql_fetch_array($result))
             {
                $_SESSION['email'] = $row['email'];

                $_SESSION['username'] = $row['username'];   
             }

        header("location: home.php");

    }

    else{

        include "photoBookProtocol.php";

                print "<br>email value after photobookprotocol file include is $email";
                print "<br>password value after photobookprotocol file include is $password";

        $obj=new Protocol();

        $var = $obj->loginCheck($email,$password);

                print "value of var received is $var";

        if($var == 0){
            session_destroy();
                        print "<br>user does not exist";
            //header("location: login.php");
        }
        else{
            $_SESSION['email'] = $var[0];
            $_SESSION['username'] = $var[1];
            print "<br>user exists";
            header("location: home.php");

        }   
    }

    mysql_close($con);
?>

So when I pass the $email and $password in loginCheck($email, $password) inside “else” clause there is nothing passed. Any idea why this is happening?

  • 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-15T04:57:15+00:00Added an answer on June 15, 2026 at 4:57 am

    There is nothing wrong with your variable scope, so either:

    • There is nothing in the POST data
    • The include overwrites the two variables
    • loginCheck() is receiving the correct variables but there is a bug within the function

    As a side note, since your script depends on POST data, you should have a condition to check if the required data is present before proceeding:

    if(isset($_POST['Email'], $_POST['Password']))
    {
        // something posted
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Java scripting and need quick help. Here is my code:
New to PHP and MySQL, have heard amazing things about this website from Leo
I'm pretty new to php, and for that matter server scripting in general (so
P.S. I am new to php & webform scripting; Currently I have the following
I'm new to PHP and web scripting in general so this a newb question.
I'm new in php and html scripting, so I would like to know if
I'm using PHP for some simple shell scripting to convert existing data into SQLite
I am trying to use a PHP form (new.php) to update 2 MySQL tables
To put it simply i am a fairly new PHP coder and i was
We are in the startup build phase of a new PHP webapp that will

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.