Page 1 of 1

Open a new page

Posted: Tue Mar 07, 2006 9:50 am
by chrislynch
Hi, I'm completely new ot php...

i have created a simple login and registration page... It all works perfectly connectingto the database, checking usernames and passwords etc

When the user enters the user name and password and its correct i want to show another webpage just saying welcome username etc etc
or incorrect username or password

How can i do this.

Chris

Posted: Tue Mar 07, 2006 9:56 am
by s.dot
either redirect to the welcome/error page using

Code: Select all

header("Location: welcome.php");
or open it in a new window (if that's what you're wanting, i'm not sure) using

Code: Select all

<form action="whatever" method="post" target="_blank">

Posted: Tue Mar 07, 2006 10:17 am
by chrislynch

Code: Select all

if($row[0]== $_POST["user_name"])
	  {
	     printf("Login successful");
	     header("Location: ./welcome.php"); 

	  }
	else
	{
		  printf("Login error");
                  header("Location: ./error.php"); 
			 
	}

I have the about code but the header function is giving the following error
Warning: Cannot modify header information - headers already sent by (output started at c:\program files\easyphp1-8\www\login.php:2) in c:\program files\easyphp1-8\www\login.php on line 35

Posted: Tue Mar 07, 2006 10:27 am
by s.dot
don't print anything before calling header("Location: xxx"); or the header won't work
instead, print "welcome" or whatever you want to say on the page you are redirecting to

Posted: Tue Mar 07, 2006 10:33 am
by chrislynch

Code: Select all

<?php
 
 //Variables used to access the database
 $hostname = "localhost";
 $database = "access_point_users";
 $username = "Chris Lynch";
 $password = "CoGiWaV5";
 
 //$user_name = $_POST["user_name"];

$ttt = mysql_connect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) 
	  {
   		$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
		}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "users")) 
{
 	
	//Selects the user_name with the entered password
	$sql = "SELECT User_Name FROM users WHERE Password = '$_POST[password]'";
 	mysql_select_db("access_point_users", $ttt) or die( "Unable to select the database");
  $Result1 = mysql_query($sql) or die(mysql_error());
	
	//Retrieves the username which matches the password
	while ($row = mysql_fetch_array($Result1, MYSQL_BOTH)) 
	{
  	//Compares the entered user name with the retrieved user name
	  if($row[0]== $_POST["user_name"])
	  {
	     //printf("Login successful");
			 header("Location: ./welcome.php");                                    
	  }
		else
		{
		 	 //printf("Login error");
			 header("Location: ./error.php")
			 
		}
  }
	

	
}
?>
Above is the php code and i still get the same error
Warning: Cannot modify header information - headers already sent by (output started at c:\program files\easyphp1-8\www\login.php:2) in c:\program files\easyphp1-8\www\login.php on line 35
chris

Posted: Tue Mar 07, 2006 10:37 am
by s.dot
Your headers are being sent by this line

c:\program files\easyphp1-8\www\login.php:2

check login.php on line 2, and remove whatever it's sending to the browser

header() only works if it's the first header being sent.. the rest of them will be ignored.

if you print out anything (even white space) you're sending a header()

Posted: Tue Mar 07, 2006 10:47 am
by chrislynch
Line two is

Code: Select all

<?php
the begining of the php code

Posted: Tue Mar 07, 2006 11:05 am
by s.dot
that's your problem, it should be line 1

the blank line before <?php is sending headers...

just erase the blank line (or any space characters) and your code should work ;)

Posted: Tue Mar 07, 2006 11:10 am
by chrislynch
Thanks its working now

Chris