I'm having some problems on gettin the Login page to redirect the users back to the login page with error message if they input the incorrect login details...

But instead of the redirect i receive an blank white screen (Nothing in View Source and Nothing on page).. How do i fix these issue.

Codes Below:

<?php
session_start();
require("db.php");
    
 
  if(isset($_SESSION['SESS_LOGGEDIN']) == TRUE) 
  {
   header("Location: " . $config_basedir);
  }
  if(isset($_POST['submit']))
  {
    $loginsql = "SELECT * FROM database_Name.users WHERE username = '" . $_POST['username'] . "' AND password = '" . $_POST['password'] . "'";
    $loginres = mysql_query($loginsql) or die (mysql_error());
    $numrows = mysql_num_rows($loginres)or die (mysql_error());
    
			if($numrows == 1)
			{
			  $loginrow = mysql_fetch_assoc($loginres);
			  
			  session_register("SESS_LOGGEDIN");
			  session_register("SESS_USERNAME");
			  session_register("SESS_USERID");
			  
			  $_SESSION['SESS_LOGGEDIN'] = 1;
			  $_SESSION['SESS_USERNAME'] = $loginrow['username'];
			  $_SESSION['SESS_USERID'] = $loginrow['id'];
			  header("Location:http://www.webaddress.com/index.php"); 
			 }
		  else
			{
			  header("Location:http://www.webaddress.com/login.php?error=1");
			}
	}
?>

Thanks in advance =)

Recommended Answers

All 8 Replies

I'm having some problems on gettin the Login page to redirect the users back to the login page with error message if they input the incorrect login details...

But instead of the redirect i receive an blank white screen (Nothing in View Source and Nothing on page).. How do i fix these issue.

Codes Below:

<?php
session_start();
require("db.php");
    
 
  if(isset($_SESSION['SESS_LOGGEDIN']) == TRUE) 
  {
   header("Location: " . $config_basedir);
  }
  if(isset($_POST['submit']))
  {
    $loginsql = "SELECT * FROM database_Name.users WHERE username = '" . $_POST['username'] . "' AND password = '" . $_POST['password'] . "'";
    $loginres = mysql_query($loginsql) or die (mysql_error());
    $numrows = mysql_num_rows($loginres)or die (mysql_error());
    
			if($numrows == 1)
			{
			  $loginrow = mysql_fetch_assoc($loginres);
			  
			  session_register("SESS_LOGGEDIN");
			  session_register("SESS_USERNAME");
			  session_register("SESS_USERID");
			  
			  $_SESSION['SESS_LOGGEDIN'] = 1;
			  $_SESSION['SESS_USERNAME'] = $loginrow['username'];
			  $_SESSION['SESS_USERID'] = $loginrow['id'];
			  header("Location:http://www.webaddress.com/index.php"); 
			 }
		  else
			{
			  header("Location:http://www.webaddress.com/login.php?error=1");
			}
	}
?>

Thanks in advance =)

Did you try check on the 'if' nesting?

Any suggestion on how to do that? =)

try check if the 'ifs' are properly nested.
when you put if and else, it should know what 'if' to 'else'!

yeah its properly nested...

line 14.. get rid of "or die(....."

Yay! Thanks soooo much! It worked... lol

I cant believe it took me that long just to figure out that the die was killin the script b.c it was turing negative... OMG

Thanks!

u welcome :-)

Yay! Thanks soooo much! It worked... lol

I cant believe it took me that long just to figure out that the die was killin the script b.c it was turing negative... OMG

Thanks!

Mark as solved if your problem is solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.