Login using PHP and MySQL not work -
i create login form using php , mysql. process if user login there database show username on page. database:
id | username | email | password --------------------------------------------------------------------------------- 1 | x | x@y.c | 642653d3f6d0a83db108b692de395f9cb8948651 2 | y | y@y.c | 642653d3f6d0a83db108b692de395f9cb8948651 3 | z | z@y.c | 642653d3f6d0a83db108b692de395f9cb8948651 4 | w | w@y.c | 642653d3f6d0a83db108b692de395f9cb8948651
and code is:
<?php define('include_check',true); require 'db.php'; session_name('fllogin'); session_set_cookie_params(2*7*24*60*60); session_start(); if($_session['id'] && !isset($_cookie['flremember']) && !$_session['rememberme']) { $_session = array(); session_destroy(); } if(isset($_get['logoff'])) { $_session = array(); session_destroy(); header("location: index.php"); exit; } if($_post['submit']=='login') { $err = array(); if(!$_post['email'] || !$_post['password']) $err[] = 'all fields must filled in!'; if(!count($err)) { $hasspass=md5($_post['password']); $_post['email'] = mysql_real_escape_string($_post['email']); $_post['password'] = mysql_real_escape_string($_post['password']); $_post['rememberme'] = (int)$_post['rememberme']; $row = mysql_fetch_assoc(mysql_query("select id,username,email database email='{$_post['email']}' , password='".$hasspass."'")); if($row['email']) { $_session['email']=$row['email']; $_session['id'] = $row['id']; $_session['username'] = $row['username']; $_session['rememberme'] = $_post['rememberme']; setcookie('flremember',$_post['rememberme']); } else $err[]='wrong email and/or password!'; } if($err) $_session['msg']['login-err'] = implode('<br />',$err); header("location: index.php"); exit; } ?> <html> <head> </head> <body> <div id="toppanel"> <div id="panel"> <div class="content clearfix"> <?php if(!$_session['id']): ?> <div class="left"> <form class="clearfix" action="" method="post"> <?php if($_session['msg']['login-err']) { echo '<div class="err">'.$_session['msg']['login-err'].'</div>'; unset($_session['msg']['login-err']); } ?> <input class="field" type="email" name="email" id="email" placeholder="email" value="" size="23" /> <input class="field" type="password" name="password" id="password" placeholder="password" size="23" /> <label><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="1" /> remember me</label> <input type="submit" name="submit" value="login" class="bt_login" /> </form> </div> <?php else: endif; ?> </div> </div> <!-- /login --> <?php echo $_session['id'] ? $_session['username'] : ' ';?> <a href="#"><?php echo $_session['id']?'<a href="?logoff">log off</a>':'log in | register';?></a> </body> </html>
its not worked. don't found error. please me.
try this:
$query = mysql_query("select id,username,email database email='{$_post['email']}' , password='".$hasspass."'"); if( mysql_num_rows($query) > 0 ) { $row = mysql_fetch_assoc($query); // save $_session values here... }else{ $err[]='wrong email and/or password!'; }
Comments
Post a Comment