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

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

the appendage is not needed you can echo out username and password within double quotes.

 

also to make the code mroe functioning you could change == to ===

 

 

also you have an extra dot like the above user stated in your SQL

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.