0

Hi there I am hoping that someone could help me with this... I was trying to redirect a page using header(); after successful login. I am going to share my codes:

Login.html

<html>
<head>
<title>HCPSMSHS: Grade Viewing System</title>

<link rel="stylesheet" href="css.css" type="text/css" charset="UTF-8" media="all">





</head>
<BODY>
<center><div id="header"></div></center>
<center>
<div id="links">
<ul class="navheader">
<li><a href="home.html"><img src="home.png"></a></li>
<li><a href="event.html"><img src="calendar.png"></a></li>
<li><a href="grade.html"><img src="user.png"></a></li>
</ul>
</div>
</center>
<center><div id="content"></div></center>
<center><div id="subcontent">
<div align="justify">
<font face="Courier New" size="1px" color="#aeaeae">
February 6, 2011, 8:21pm</font><br/>
<font face="georgia" size="5px">
Log in</font>
<hr>
<center>
<form name="myform" action="script1.php" method="post">

<table width="500" border="0" cellpadding="1" cellspacing="1">
<tbody>
<tr>
	<td width="30%" height="40">
	<font size="5px">User Name</font>
		<td><input type="text" name="username"  size="40px" maxlength=25> <br/>
<tr>
	<td width="30%" height="40">
	<font size="5px">Password</font>
		<td><input type="password" name="password"  size="40px" maxlength=25> <br/>
<tr>
	<td colspan="2"><center><input type="submit" name="submit" width="5"> <input type="button" value="Cancel"></center>
</table>

</form>
</center>
</div></center>


</html>

Script1.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="css.css" type="text/css" charset="UTF-8" media="all">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php

$conn=odbc_connect('MS Access Driver','','')
or die("connect error: ".odbc_error());

$username=trim(stripslashes($_POST['username']));
$password=trim(stripslashes($_POST['password']));

$sql="SELECT * FROM tbllogin WHERE username='$username' and password='$password'";


$result=odbc_exec($conn,$sql)
or die ("result error ".odbc_error().'-'.odbc_errormsg());

// if no result: no rows read
if (!odbc_fetch_row($result))
{
echo "<script>alert(\"ERROR! Try again.\");</script>";
}

// else: all is okay
else {

$_SESSION['username']=$username;
$_SESSION['password']=$password;
echo "<script>alert(\"Welcome $username!!\")</script>";
header("Location: grade.php");
}
odbc_close($conn);
?>

</body>
</html>

When I try to load these I receive this error:


Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\web\script1.php:10) in C:\xampp\htdocs\web\script1.php on line 36

line 36 points to the header() code. >.<
can anyone help me with these?

2
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by kitschkath
0

the problem as i see it is that header syntaxing is correct but
* Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. *

0

So it means that I am going to put the header on the first part of the code? Where exactly? Sorry I am a noob in PHP, I just started yesterday >.<

0

ok so basically when your code executes in that line you shouldnt have a echo or print before header

obviously put line no: 35 below because thats one echo thats coming before the header

0

^ Okay so I put the header before the echo and I still got the same error. Is there any code for redirecting a page other than header?

0

Thank you I already solved the problem using an alternative script!

here it is:

print "<script>";
print " self.location='mynewpage.html';";
print "</script>";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.