I have a process page for logging in, I can connect to the database, and also check the username and password.
but after that I can’t show the index page after a successful login. This is my code:
$dbc=mysql_connect(_SRV,_ACCID,_PWD) or die(_ERROR15.": ".mysql_error());
$db=mysql_select_db("qdbase",$dbc) or die(_ERROR17.": ".mysql_error());
switch(postVar('action')) {
case 'submitlogin' :
submitlogin(postVar('loguser'),postVar('logpass'));
break;
}
function submitlogin($loguser,$logpass){
if(isset($loguser, $logpass)) {
ob_start();
$myusername = stripslashes($loguser);
$mypassword = stripslashes($logpass);
$myusername = mysql_real_escape_string($myusername,$dbc);
$mypassword = mysql_real_escape_string($mypassword, $dbc);
$sql="SELECT * FROM admin WHERE user='$myusername' AND password=('$mypassword')";
$result=mysql_query($sql, $dbc);
$count=mysql_num_rows($result);
if($count==1){
session_register("admin");
session_register("password");
$_SESSION['name']= $myusername;
header("location:index1.php");
}
else {
$msg = "Wrong Username or Password. Please retry";
header("location:login.php?msg=$msg");
}
}
else {
header("location:login.php?msg=Please enter some username and password");
}
mysql_close($dbc);
ob_end_flush();
}
Can you help me solve this problem?
EDIT
I got confused in this part from index1.php:
<?php
session_start();
define(ADMIN,$_SESSION['name']);
if(!session_is_registered("admin")){
header("location:login.php");
}
else
header( 'Content-Type: text/html; charset=utf-8' );
?>
and this part is from login.php because I think they are not syncing:
if(mysql_num_rows($result) > 0)
{
session_register("admin");
session_register("password");
$_SESSION['name']= $myusername;
header("location:index1.php");
}
I only have a user and password, where does it come from admin? bcoz from this i get:
PHP Notice: Use of undefined constant ADMIN - assumed 'ADMIN' in /var/www/html/index1.php on line 12
source
share