Log in script


#1

Checklogin.php
[php]

<?php $db_host = "mattsminimart.co.uk.mysql"; $db_username = "mattsminimart_c"; $db_pass = "********"; $db_name = "mattsminimart_c"; $tbl_name = "admin"; mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql"); mysql_select_db("$db_name") or die ("no database"); //user and pass from form $myusername = $_POST['myusername']; $mypassword = $_POST['mypassword']; $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register("myusername"); session_register("mypassword"); header("location:login_success.php"); } else{ echo "You have entered the Wrong username or password"; } ?>

[/php]

login_success.php
[php]<?

session_start();

if!session_is_registered(myusername)){

header("location:admin.php");

}

?>

#header { width:100%; height:50px; background-color:#03C; border:#000 1px solid; color:#FFF; text-align:center; } #wrap { margin:0 auto; width:100%; height:auto; text-align:center; } #login { div-align:center; margin: 0 auto; width:400px; height:300px; margin-top:100px; } .textinput { border-radius:5px; width:200px; } .label { disply:block; font-weight:bold; } #footer { width:100%; height:30px; background-color:#03C; } #footer h3 { text-align:center; color:#FFF; } #footer h4 { float:right; color:#F00; } Untitled Document

Admin Area

YOU HAVE LOGGED IN

copyright

[/php] admin.php [code]

#header {

width:100%;

height:50px;

background-color:#03C;

border:#000 1px solid;

color:#FFF;

text-align:center;

}
#wrap {
margin:0 auto;
width:100%;
height:auto;
text-align:center;
}

#login {
div-align:center;
margin: 0 auto;
width:400px;
height:300px;
margin-top:100px;
}

.textinput {

border-radius:5px;

width:200px;

}

.label {

disply:block;

font-weight:bold;

}

#footer {

width:100%;

height:30px;

background-color:#03C;

}

#footer h3 {

text-align:center;

color:#FFF;

}

#footer h4 {

float:right;

color:#F00;

}

Untitled Document

Admin Area

Log In

username:

password:

copyright

[/code]

al as i get when the form is submitted is it saying You have entered the Wrong username or password

so i assume there is something wrong with

[php]if($count==1){

session_register("myusername");

session_register("mypassword");

header("location:login_success.php");

}[/php]

reagrds

karl


#2
hello karlc87, i think you have to start session before resister any variable.

[php]
if($count==1){
session_start();
session_register(“myusername”);
session_register(“mypassword”);
header(“location:login_success.php”);
}
[/php]
i hope this will helpful for you.
SR