php - How to write one login form for both the admin and the user -
i'm trying write code takes 2 input values( username , password) , compare them values in table (named user) in database. now, if value inserted username "admin" , password "admin". want direct admin page, , if user has inserted info, want direct him page also. codes below correct im giving no response. how can fixed
i wrote code html
<form name="userlogin" action="logincode.php" method="post" > <h3>login</h3> <table width="450px"> <tr> <td valign="top"> <label for="first_name">your name *</label> </td> <td valign="top"> <input type="text" name="user_username" maxlength="50" size="30" required> </td> </tr> <tr> <td valign="top"> <label for="last_name">password *</label> </td> <td valign="top"> <input type="password" name="user_password" maxlength="50" size="30" required> </td> <tr> <td></td> <td><input type="submit" name="login" value="login" required> </td> </tr> </table> </form> and logincode.php
<?php include ("../connections/map_connection.php"); if (isset($_post["login"])) { $user_username = $_post["user_username"]; $user_password = $_post["user_password"]; /* $user_email=$_post["user_email"]; */ if ($username = 'admin' , $user_password = 'admin') { $data = mysql_fetch_array($result); session_start(); $_session['name'] = $data['user_username']; $_session['start'] = time(); $_session['expire'] = $_session['start'] + 400; header("location: ..admin/adminindex.php"); } else { $sql = ("select * user user_username='$user_username' , user_password= '$user_password' "); $result = mysql_query($sql); if (!$result) { echo "error" . mysql_error(); } else { $row = mysql_num_rows($result); if ($row == 0) { echo 'invalid username or password'; } else { $data = mysql_fetch_array($result); session_start(); $_session['name'] = $data['user_username']; $_session['start'] = time(); $_session['expire'] = $_session['start'] + 400; header("location: userindex.php"); } } } } ?>
check if condition,
if ($username = 'admin' , $user_password = 'admin') here using single '=' i.e assignment operation instead of comparison i.e '=='.
try :
if ($username == 'admin' && $user_password == 'admin') :::::::::::::::::::::::update:::::::::::::::::::::::::
what mean?
if ($username == 'admin' && $user_password == 'admin') { $data = mysql_fetch_array($result); .... } my point without mysql_query() using mysql_fetch_assoc().
Comments
Post a Comment