thanks for all the help 🙂, i got it all working, except for one thing, how can i protect webpages being veiwed before the user has logged in?
and also, is this code secure now? i'm not sure whether i did the escape strings right
<?php
$server = "localhost";
$username = "root";
$password = "";
$datebase = "login";
print '<div class="result">';
print "<a href=\"loginframe.php?action=yes\">Login?</a>";
echo '<script>window.open("main.php","main")</script>';
print '</div';
if (isset($action) && $action == 'yes') {
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>?action=login" method="post"><div class="form">
<label for="name">Username : </label></div>
<input name="u" type="text" class="textfield" id="u" maxlength="8" />
<div class="form"><label>Password : </label></div>
<input name="p" type="password" class="textfield" id="p" maxlength="8" /><br/>
<input name="submit" type="image" src="login.png" id="submit" value="submit" />
</form>
<?php
$url2 = "http://localhost/main.php";
$url = "http://localhost/admin.php";
}
$db = mysql_connect($server, $username, $password);
$username = mysql_escape_string($_POST['u']);
$password = mysql_escape_string($_POST['p']);
mysql_select_db($datebase, $db);
$result = mysql_query("SELECT * FROM users WHERE username='$u'",$db) or die(mysql_error());
while ( $r = mysql_fetch_array( $result ) ) {
$uu = $r['username'];
$pp = $r['password'];
$gg = $r['group'];
}
if (isset($action) && $action == 'login') {
if ($u == ""){
echo "Please Input Your Details!";
}else
if ($uu == $u && $pp == $p && $gg == 'admin'){
echo '<div class="result">Logged In As: ' . $uu . '</div>';
echo '<script>window.open("admin.php","main")</script>';
}else
if ($uu == $u && $pp == $p && $gg == 'user'){
echo '<div class="result">Logged In As: ' . $uu . '</div>';
echo '<script>window.open("main.php","main")</script>';
}else
echo '<div class="result"> Wrong<br>Username/Password!</div>';
}
?>