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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:19:43+00:00 2026-05-20T16:19:43+00:00

<?php $link = mysql_connect(‘127.0.0.1’, ‘ilhan’, ‘password123’); if(!$link) { die(‘Could not connect: ‘ . mysql_error());

  • 0
<?php
$link = mysql_connect('127.0.0.1', 'ilhan', 'password123');
if(!$link)
    {
        die('Could not connect: ' . mysql_error());
    }
mysql_select_db("metu", $link);
mysql_set_charset('utf8',$link);

if(isset($_POST["email"])) // AND strlen($_POST["email"])>1 solves the problem
//  but I didn't get why the page is redirected...
    {
        $email = mysql_real_escape_string($_POST["email"]);
        $password = mysql_real_escape_string($_POST["password"]);

        $result = mysql_query("SELECT password, id FROM users WHERE email = '$email'");

        if (!$result)
            {
                die('Invalid query: ' . mysql_error());
            }

        $row = mysql_fetch_assoc($result);

        if($row['password'] == $password) 
            {
                $_SESSION['valid_user'] = $row['id'];
                mysql_close($link);
                header("Location: http://www.example.com");
            }
        else $login = false;


        mysql_close($link);
    }
else $login = false;
?>

Do you think that the page will be redirected if the user submits a blank email and blank password? It shouldn’t but the page is redirected. Why is that? Bug?

  • 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-20T16:19:44+00:00Added an answer on May 20, 2026 at 4:19 pm

    I’ve overlooked the issue at first.
    here it is:

    if($row['password'] == $password) 
    

    empty $row['password'] is equal to empty $password. evaluated to true

    here is what I’d do it

    <?php
    include 'db.php';    
    if(isset($_POST["email"]))
    {
        $sql = "SELECT id FROM users WHERE email='%s' AND password='%s'";
        $id  = dbGetOne($sql,$_POST["email"],MD5($_POST["email"].$_POST["password"]));
        if($id) 
        {
            $_SESSION['valid_user'] = $row['id'];
            header("Location: http://www.example.com");
            exit;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<?php /** Connect to DB */ mysql_connect(localhost, dbuser, pass) or die(mysql_error()); mysql_select_db(dbname) or die(mysql_error());
<?php $objConnect = mysql_connect(localhost,,root) or die(mysql_error()); $objDB = mysql_select_db(mydb); $pic2 = SELECT * FROM
<?php $con = mysql_connect (localhost, user, pass) or die ('Error: ' . mysql_error()); mysql_select_db
I have the code below: <?php $con = mysql_connect(localhost,will,blahblahblah); if (!$con) { die('Could not
I have the code below: <html><body> <?php $con = mysql_connect(localhost,will,blahblah); if (!$con) { die('Could
Heres my script for my homepage: <?php include('inc/connect.php'); mysql_select_db(hub); ?> <html> <head> <title>CyberBat -
I have borrowed code from this link PHP regex templating - find all occurrences
Can anyone tell me if its possible to validate a link with php? By
I have two PHP files that I need to link. How can I link
Heres my link: http://tinyurl.com/6j727e If you click on the link in test.php, it opens

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.