Jump to content

Recommended Posts

ok all im trying to do is in the usrname fielf if i enter the correct value which is in db then it says user exist and if not the says user does not exist. here is my coding could someone help?

 

<html>
    <head>
        <title>Login</title>
	<link rel="stylesheet" type="text/css" href="style/login.css" media="all">
    </head>
    <body>

<div id="form_align"> 
        
        <form action="login.php" method="post" name="frm_login">
		Username: 
		<input type="text" name="txt_username"/><br />
		Password:
		<input type="password" name="txt_pass"/><br />
		<input type="submit" name="sub" value="Login">

        </form>
        
        
        </div>
    </body>
</html>


<?php

if(! $conn=mysql_connect("localhost", "root", "demo"))
die("Could't connect to database server..");
mysql_select_db("online_application",$conn) or die(mysql_error());

$username   = $_POST['txt_username'];
$password   = $_POST['txt_pass'];

$sql = " SELECT * FROM users WHERE user_name='".$username."' AND password='".$password."'";
//$result = mysql_query($sql);



if(){
    print 'user exists';   
}
else{
    print 'User does not exists';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/201152-how-will-the-statement-be/
Share on other sites

i use md5 bro and thanks for the helps and time :-)

 

are you sure?

 

$username   = $_POST['txt_username'];
$password   = $_POST['txt_pass'];

$sql = " SELECT * FROM users WHERE user_name='".$username."' AND password='".$password."'";
//$result = mysql_query($sql);

 

The code above takes a plain and unsanitized password from $_POST. I don't see where you are md5ing the posted password

 

If you are using md5 to hash the password when the user registers you will also need to use it to check their password when they login. Here is an example of how I would do it(using your existing code)

if(! $conn=mysql_connect("localhost", "root", "demo"))
die("Could't connect to database server..");
mysql_select_db("online_application",$conn) or die(mysql_error());

$username   = mysql_real_escape_string(trim($_POST['txt_username']));
$password   = md5(mysql_real_escape_string(trim($_POST['txt_pass'])));

$sql = " SELECT * FROM users WHERE user_name='".$username."' AND password='".$password."'";
$res= mysql_query($sql)
$login_match= mysql_result($res, 0, 'login_match'); 



if($login_match == 1){
    print 'user exists with that password';   
}
else{
    print 'User does not exists with that password';

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.