Jump to content

how will the statement be?


xcoderx

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';

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.