hi guys i need some help with my code
im new to php and im trying to create a login page.
i have created MYSQL database to go along but whenever i try to login - it brings me to myaccount.php and just displays Access Denied no matter what input, be it in the database or just plain rubbish.
Hope you guys can help me out as ive been messing around with it for a day :$
<?php
include 'dbc.php';
$user_name = mysql_real_escape_string($_POST['name']);
if ($_POST['Submit']=='Login')
{
$md5pass = md5($_POST['pwd']);
$sql = "SELECT user_pwd FROM users WHERE
user_name = '$_POST[user_name]'";
$result = mysql_query($sql) or die (mysql_error());
if ( $result = $md5pass )
{
// A matching row was found - the user is authenticated.
session_start();
list($md5pass,$user_name) = mysql_fetch_row($result);
// this sets variables in the session
$_SESSION['user']= $user_name;
if (isset($_GET['ret']) && !empty($_GET['ret']))
{
header("Location: $_GET[ret]");
exit();
} else
{
header("Location: myaccount.php");
exit();
}
//echo "Logged in...";
exit();
}
header("Location: login.php?msg=Invalid Login");
//echo "Error:";
exit();
}
?>
<link href="styles.css" rel="stylesheet" type="text/css">
<?php if (isset($_GET['msg'])) { echo "<div class=\"msg\"> $_GET[msg] </div>"; } ?>
<p> </p><table width="40%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#d5e8f9" class="mnuheader" >
<div align="center"><font size="5"><strong>Login
Members</strong></font></div></td>
</tr>
<tr>
<td bgcolor="#e5ecf9" class="mnubody"><form name="form1" method="post" action="">
<p> </p>
<p align="center">Username
<input name="username" type="text" id="user_name">
</p>
<p align="center"> Password:
<input name="pwd" type="password" id="pwd">
</p>
<p align="center">
<input type="submit" name="Submit" value="Login">
</p>
<p align="center"><a href="register.php">Register</a> | <a href="forgot.php">Forgot</a></p>
</form></td>
</tr>
</table>
<?php
session_start();
if (!isset($_SESSION['user']))
{
die ("Access Denied");
}
?>
<h2>My Account </h2>
<?php if (isset($_SESSION['user'])) { ?>
<p>Logged as <?php echo $_SESSION['user']; ?> | <a href="settings.php">Settings</a>
| <a href="logout.php">Logout</a> </p>
<?php } ?>