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 } ?>
Below takes the URL varible admin checks to see if its defined and if so it opens a connection to MYSQL. the require_once was made by dreamweaver to get the connection.
<?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,$ok) or die("Query failed ($query): " . mysql_error());
$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 the error below...
Query failed (SELECT loginName, passWord FROM users WHERE passWord = 'useradmin'): No database selected