Im trying to create a login form that ask for login name and password. once submited, the form submits to the same page again but assigns the value 1 to the URL varible. An If statement gets the URL varible and begins to check if the login name and password is correct. See script below
Below starts a session. if the user session is not defined the display the login form.
<?php session_start(); ?>
<?php if ( !isset($_SESSION['user'])){ ?>
<table border="0" cellspacing="0" cellpadding="0">
<form action="admin.php?admin=1" method="post">
<tr>
<td width="82">Login:</td>
<td width="144"><input type="text" name="loginName" /></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="login" /></td>
</tr>
</form>
</table>
<?php } ?>
As you can see from the top script. once the form is submited the value 1 is assigned to the URL varible admin. the below script checks to see if the URL admin ==1 if so then it creates a connection. Im using dreamweaver so dreamweaver creates a require_once to the document ok.php which connects to mySQL. the connection works. from then on Im not sure what I did wrong.
<?php if ($_GET['admin'] == 1){ ?>
<div id="admin">
<?php require_once('Connections/ok.php'); ?>
<?php $query = "SELECT loginName, passWord
FROM users
WHERE passWord = '$_POST[password]'";
mysql_select_db(database_ok,$ok);
$results = mysql_query($query);
$check = mysql_fetch_assoc($results);
if (strcasecmp($check['loginName'],$_POST['loginName']) == 0
&& strcmp($check['passWord'],$_POST['password']) == 0) {
echo "success";
}else { echo "Wrong"; }
?>
</div>
<?php }?>
In the end I get this error once I submit the form.
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\www\apache\htdocs\admin.php on line 48
Wrong
anyone have any suggestions ??