Jump to content

Unable to do SELECT function, its strange..


ankur0101

Recommended Posts

Hi,

I am making a login page which consists of 2 pages, index.php and config.php

 

Following is a code of config.php

<?php
define("HOST", "localhost");
define("USER", "aaaabbbccc");
define("PASS", "aaabbbccc");
define("DATABASE", "pricetagindia");

$connection = @mysql_connect(HOST, USER, PASS);
$select_db = @mysql_select_db(DATABASE, $connection);

if(!$connection)
{
    echo "<h1>Cannot connect to database</h1>";
    exit(0);
    }
if(!$select_db)
{
    echo "<h1>Cannot select database</h1>";
    exit(1);
    }


?>

 

 

Here is a coding of index.php

<?php
include('config.php');

$_error = "<p></p>";
if (isset($_POST['username']) || isset($_POST['password']))
{
    $username = $_POST['username'];
    $password = $_POST['password'];
    
    if($username == NULL || $password == NULL)
    {
        $_error = "<p>Username and Password, both fields are required.</p>";
        }
    else
    {
        // Check in DB
        $password = md5($password);
        $checkuser_query = "SELECT * FROM users WHERE username = '$username.' AND password = '$password'";
        $checkuser_result = mysql_query($checkuser_query);
        $checkuser_count = mysql_num_rows($checkuser_result);
        if($checkuser_count == 1)
        {
            echo "match found";
            }
        else
        {
            echo "nothing found error, username was ".$username." and pass is ".$password;
            echo "<p></p>";
            echo $checkuser_result;
            }
    
                
        
        
        
        }
    
    
    
    
    
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Price Tag India</title>
</head>

<body>
<center>
  <h1>Price Tag India</h1>
  <p> </p>
</center>
<center>
<form action="index.php" method="post" target="">
<table width="389" height="168" border="0">
  <tr>
    <td width="141">Username :</td>
    <td colspan="2"><label for="username"></label>
      <input type="text" name="username" id="username" /></td>
  </tr>
  <tr>
    <td>Password :</td>
    <td colspan="2"><label for="password"></label>
      <input type="password" name="password" id="password" /></td>
  </tr>
  <tr>
    <td> </td>
    <td width="56"><input type="submit" name="button" id="button" value="Submit" /></td>
    <td width="223"><input type="reset" name="button2" id="button2" value="Reset" /></td>
  </tr>
  <tr>
    <td> </td>
    <td colspan="2">
    <?php 
    echo $_error;
    ?>
    </td>
  </tr>
</table>
<p> </p>
</form>
</center>
</body>
</html>

 

I have attached the screenshot of database.

 

Problem is when I do valid login i.e. with user admin and its password, it is not working, I spent 1 hour for solving this issue but didnt find any solution.

Its frustrating now.....I know its simple but still its not working.

 

It is giving me error as

nothing found error, username was admin and pass is 62cc2d8b4bf2d8728120d052163a77df
Resource id #5 

post-66625-13482403473694_thumb.jpg

Check your SQL for fetching the user.  You have a period appended to the username:

 

$checkuser_query = "SELECT * FROM users WHERE username = '$username.' AND password = '$password'";

 

So if you enter "admin" as the username, your query is trying to find "admin." (i.e. with a period at the end).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.