473,467 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Page Redirecting Problem

30 New Member
hi guyz, i have a difficulty in understanding the header function. they said that you must first call the header function before any output on the page will make?is that right?

because i create a simple login which when the user click the button submit the query for searching of registered user will execute and will redirect to index.php.after i click the submit here is the error that give's me Warning: Cannot modify header information - headers already sent by (output started at C:\kamote\HelloDatabase2.php:6) in C:\kamote\HelloDatabase2.php on line 65

HERE IS MY CODE

[PHP]<HTML>
<HEAD>
<TITLE>New Document</TITLE>
</HEAD>
<BODY>
<?
if (!isset($_POST['submit'])) {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border=0 cellspacing=10 align=center width=100%>
<tr>
<td align=center style="font-size:50px; background-color:#284775; color:#eeeeee">Login</td>
</tr>
<tr>
<td>
<table border=0 width=50% align=center>
<tr>
<td colspan=2>&nbsp;</td>
</tr>
<tr>
<td colspan=2 style="background-color:#5d7b9d;color:#ffffff;font-weight:bold">Login status:</td>
</tr>
<tr>
<td align="right">Username:</td>
<td><input type="text" name="tusername" size="40">
</tr>
<tr>
<td align="right">Password:</td>
<td><input type="password" name="tpassword" size="40">
</tr>
<tr>
<td></td>
<td><a href="#">Forgot your password?</a> <a href="#">Register?</a></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Login"></td>
</td>
</table>
</td>
</tr>
</table>
<p align=center style="font-size:9pt">Copyright Microkups Co, Inc. © 2007</p>
</form>
<?
}

else {

$server = "localhost";
$user = "root";
$pass = "";
$db = "mydbase";

$uname = $_POST['tusername'];
$upass = $_POST['tpassword'];

$connection = mysql_connect($server,$user,$pass) or die("Unable to connect");
mysql_select_db($db);
$query = "Select * from tblUsers Where username = '$uname' and password = '$upass'";
$result = mysql_query($query) or die("Error in query");

if (mysql_num_rows($result) > 0) {
echo "you successfully logged as $uname";
header ('Location: index.php');
}

else {
echo "invalid username or password";
}

}
?>
</BODY>
</HTML>[/PHP]
Oct 15 '07 #1
4 1404
nathj
938 Recognized Expert Contributor
hi guyz, i have a difficulty in understanding the header function. they said that you must first call the header function before any output on the page will make?is that right?
Hi Klaydze,

Anything that writes to the browser, such as HTML tags, echo, printf, print_r etc MUST go AFTER the header() function. The manual is correct, header() HAS TO BE the first thing output.

This also includes spaces, see the PHP Manual for headers.

Cheers
nathj
Oct 15 '07 #2
ronverdonk
4,258 Recognized Expert Specialist
It would be the simplest way to leave the echo out:
[php]
if (mysql_num_rows($result) > 0) {
header ('Location: index.php');
}
[/php]
or pass the message to index.php, so you can display it there:
[php]
if (mysql_num_rows($result) > 0) {
header ('Location: index.php?msg=successful');
}
[/php]

Ronald
Oct 15 '07 #3
klaydze
30 New Member
It would be the simplest way to leave the echo out:
[php]
if (mysql_num_rows($result) > 0) {
header ('Location: index.php');
}
[/php]
or pass the message to index.php, so you can display it there:
[php]
if (mysql_num_rows($result) > 0) {
header ('Location: index.php?msg=successful');
}
[/php]

Ronald
still it gives me this error Warning: Cannot modify header information - headers already sent by (output started at C:\kamote\HelloDatabase2.php:6) in C:\kamote\HelloDatabase2.php on line 65

other way to fixed this? thank you
Oct 25 '07 #4
ak1dnar
1,584 Recognized Expert Top Contributor
still it gives me this error Warning: Cannot modify header information - headers already sent by (output started at C:\kamote\HelloDatabase2.php:6) in C:\kamote\HelloDatabase2.php on line 65

other way to fixed this? thank you
Instead of using like this
Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <HEAD>
  3. <TITLE>New Document</TITLE>
  4. </HEAD>
  5. <BODY>
  6. <?
  7. php codes
  8. ?>
  9.  
try to put, php opening tags with out any white space on the top of the page
Expand|Select|Wrap|Line Numbers
  1. <?
  2.  php codes
  3.  ?>
  4. <HTML>
  5. <HEAD>
  6. <TITLE>New Document</TITLE>
  7. </HEAD>
  8. <BODY>
  9.  
and never use short tags <?......?> instead use of use <?php........?>
Oct 25 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: lozd | last post by:
Would appreciate any solutions people could offer for this. Basically I wan't to use a frameset with an aspx page as the contents rather than a htm page and I'd like to be able to redirect the...
6
by: John Lau | last post by:
Hi, I am looking at the MS KB Article 306355: HOW TO: Create Custom Error Reporting Pages in ASP.NET by Using Visual C# .NET This article describes how to redirect errors to a custom html...
9
by: Paul | last post by:
What I am trying to do is as follows. I have a page with 3 links,that direct the user to 3 different pages when selected after login. So all link selections will first direct the user to a login...
1
by: craigkenisston | last post by:
Hi, I'm going nuts with a supposed simple thing. I have this page : <%@ Page language="c#" Codebehind="404page.aspx.cs" AutoEventWireup="false" Inherits="mydomain._404page" %> <!DOCTYPE HTML...
4
by: Greg Smalter | last post by:
Redirecting from page to page within a web project is pretty easy. However, all Redirect methods take strings as arguments, as if you mistype the string, you don't find out until run time that you...
4
by: deepukutty | last post by:
HI all, I am using IE(Internet Explorer) as my default browser for asp.net application development. Today i faced a strange problem. When ever an exception occured in the page ....application...
7
by: Pat Carden | last post by:
I'm trying to provide a better user experience by redirecting my users to a "Page Not Found" page, using a Custom Errors directive in Web.Config. The problem is I need to return a 404 error code...
4
by: shapper | last post by:
Hello, I am using the following code line in my VB code to redirect to another page inside my web site: Response.Redirect("Message.aspx") I am getting the error: The page isn't redirecting...
1
by: kang jia | last post by:
hi when user entered particulars in signuppage and click" signup" button, i will direct them to do_signup.php. if say the NRIC is dupicate in datebase, i will redirect them back to signup page...
7
by: Jonathan Wood | last post by:
My site requires all users to log on. Depending on the user's role, they will have access to a certain set of pages. I implemented this by redirecting the user to the appropriate home page in...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.