Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 953 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

a problem need php and mysql programmer to solve it,it's not big problem

Thread title: a problem need php and mysql programmer to solve it,it's not big problem
Reply  
Page 1 of 2 1 2 >
    Thread tools Search this thread Display Modes  
06-29-2009, 10:32 PM
#1
free-designer is offline free-designer
Status: Junior Member
Join date: Jun 2009
Location:
Expertise:
Software:
 
Posts: 98
iTrader: 0 / 0%
 

free-designer is on a distinguished road

  Old  a problem need php and mysql programmer to solve it,it's not big problem

hey people im still working on my first project that users can register and just login the register page work preeeeety fine and good.
i have an index.php witch's where people will login and my base.php file that hold my database details
here is the code of the base.php

PHP Code:
<?php
session_start
();

    
// DATABASE CONSTANTS
    
define("DB_SERVER","localhost");//it's better to leave it "localhost"
    
define("DB_USER","root");//The defult user "root:
    
define("DB_PASS","");//type ur database password if u have
    
define("DB_NAME","userslogin");//the database name u've setup

    //the database connection
    
$connection mysql_connect(DB_SERVER,DB_USER);
    if(!
$connection){
        die(
"Database connection failed: " mysql_error());
    }
    
    
//select database
    
$db_select mysql_select_db(DB_NAME$connection);
    if(!
$db_select){    
        die(
"database selection failed:" mysql_error()); 
    }
?>

and here is the index.php file code
PHP Code:
<?php require_once("base.php"); ?>
<html>
    <head>
        <title>User Login</title>
    </head>
    <style>
        body{background:#dbdbdb; margin:0; padding:0; font:'Verdana', Geneva, sans-serif;}
    </style>
    <link href="stylesheets/style.css" media="all" rel="stylesheet" type="text/css" />
    <body>
    
        <div id="box_outter">
        
        
            <div id="box_bg">
                <div class="header">
                <img src="images/logo.gif" alt="Logo" class="logo">
                <img src="images/bigman.jpg" alt="bigman" class="bigman">
                </div>
                
    <?php
        
if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['username']))
        {
             
?>
            
             <p>Welcome back<?=$_SESSION['username']?>.</p>
            
            <ul>
                <li><a href="logout.php">Logout.</a></li>
            </ul>
            
            <?php
        
}
        
        elseif(!empty(
$_POST['username']) && !empty($_POST['password']))
        {
            
$username mysql_real_escape_string($_POST['username']);
            
$password md5(mysql_real_escape_string($_POST['password']));
            
            
$checklogin mysql_query("SELECT * FROM users WHERE username = '".$username."' AND password = '".$password."'");
            
            if(
mysql_num_rows($checklogin) == 1)
            {
                 
$row mysql_fetch_array($checklogin);
                
                
$_SESSION['username'] = $username;
                
$_SESSION['LoggedIn'] = 1;
                
                echo 
"<p>you now logged in successfully</p>";
                echo 
"<meta http-equiv='refresh' content='=3;index.php' />";
            }
            else
            {
                echo 
"<p>this user dose not exist</p>";
            }
            
        }
        else
        {
      
?>
            <div class="body">
                <div class="login_box">
                <h1 class="li-h"></h1>
                <form action="index.php" method="post" class="login_box_out">
                
                    <input type="text" name="username" class="user_form" value="Username" 
                    onfocus="if(this.value=='Username'){this.value=''};" onBlur="if(this.value==''){this.value='Username'};">
                    
                    <input type="password" name="password" class="pass_form" value="password" 
                    onfocus="if(this.value=='password'){this.value=''};" onBlur="if(this.value==''){this.value='password'};">
                    
                    <input type="submit" name="login" class="login_btn" value=" ">
                </form>
                <a href="register.php" class="reg-link">Register</a>
                </div>
            </div>
            <?php  ?>
            </div>
        </div>
       
    </body>
</html>
<?php 
    mysql_close
($connection);
?>
please take a good look to this index.php
i have in my database tow usernames the first one is {mohsen} and the second one is {test}
while i write in the tow forms the username and the password like this
{more details in the image}



while i click on login button i get "this user dose not exist"
like this {more details in the image}

my problem is that i have that username and password in my database and he can't found it can anyone please help me and tell me what is my fult in the code that made it get me the else statement
thanx for anyhelps

Reply With Quote
06-30-2009, 08:30 AM
#2
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

What is the password for the test user, and what is stored in the password column in the database for that user?

Reply With Quote
06-30-2009, 09:56 AM
#3
free-designer is offline free-designer
Status: Junior Member
Join date: Jun 2009
Location:
Expertise:
Software:
 
Posts: 98
iTrader: 0 / 0%
 

free-designer is on a distinguished road

  Old

the password for the test user is {test}

and this is how the password column look like in the database



the password have been hashed cuz of md5 function
right???

Reply With Quote
06-30-2009, 01:22 PM
#4
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

The MD5 value for test is 098f6bcd4621d373cade4e832627b4f6. Why are only the first twenty characters being shown in your phpMyAdmin screenshot, what type is the password column set as? CHAR(20)?

Reply With Quote
06-30-2009, 02:07 PM
#5
free-designer is offline free-designer
Status: Junior Member
Join date: Jun 2009
Location:
Expertise:
Software:
 
Posts: 98
iTrader: 0 / 0%
 

free-designer is on a distinguished road

  Old

CREATE TABLE users(
userid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(30),
password VARCHAR(20),
email VARCHAR(220)
);

this is how i created the users table
yes it is 20 CHAR
do you mean that it have to be more then 20 cuz the md5 function going to make the {test} password more then 20 char's that why he always tellin me this user dose not exist cuz he is only read 20 ???

Reply With Quote
06-30-2009, 02:19 PM
#6
Immersion is offline Immersion
Status: Senior Member
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 918
iTrader: 5 / 100%
 

Immersion is on a distinguished road

  Old

The md5 function creates a 32 character string. Storing it in a 20 character field will cut off some of the password. You need to change your password varchar to 32.

Reply With Quote
06-30-2009, 02:22 PM
#7
free-designer is offline free-designer
Status: Junior Member
Join date: Jun 2009
Location:
Expertise:
Software:
 
Posts: 98
iTrader: 0 / 0%
 

free-designer is on a distinguished road

  Old

Originally Posted by Immersion View Post
The md5 function creates a 32 character string. Storing it in a 20 character field will cut off some of the password. You need to change your password varchar to 32.
that exactly what i've done and it's working pretty well now thank you for your help

Reply With Quote
06-30-2009, 02:23 PM
#8
free-designer is offline free-designer
Status: Junior Member
Join date: Jun 2009
Location:
Expertise:
Software:
 
Posts: 98
iTrader: 0 / 0%
 

free-designer is on a distinguished road

  Old

Salathe

i get your point and i have change it tow 32 and it's working pretty well now
thanks for the help again.

Reply With Quote
06-30-2009, 04:13 PM
#9
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

No problem. Good work on changing the password to 32 characters, making it work properly! Note, it can be CHAR(32) instead of VARCHAR(32) if it is not already... there is no need to use a variable-length type (VARCHAR) on something that will always be a fixed length.

Reply With Quote
06-30-2009, 04:36 PM
#10
Immersion is offline Immersion
Status: Senior Member
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 918
iTrader: 5 / 100%
 

Immersion is on a distinguished road

  Old

However changing from varchar to char will make very little, if no, difference on the speed of the queries.

Reply With Quote
Reply  
Page 1 of 2 1 2 >


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed