Open a new page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chrislynch
Forum Newbie
Posts: 9
Joined: Tue Mar 07, 2006 9:44 am

Open a new page

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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">
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
chrislynch
Forum Newbie
Posts: 9
Joined: Tue Mar 07, 2006 9:44 am

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
chrislynch
Forum Newbie
Posts: 9
Joined: Tue Mar 07, 2006 9:44 am

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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()
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
chrislynch
Forum Newbie
Posts: 9
Joined: Tue Mar 07, 2006 9:44 am

Post by chrislynch »

Line two is

Code: Select all

<?php
the begining of the php code
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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 ;)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
chrislynch
Forum Newbie
Posts: 9
Joined: Tue Mar 07, 2006 9:44 am

Post by chrislynch »

Thanks its working now

Chris
Post Reply