i am using the following code and i keep getting
<?
session_start();
include(“dbblsr.php”);
mysql_select_db(“cgowie_teamcanada”, $conn);
$result = mysql_query(“SELECT * FROM teamcanada WHERE reqemail=’$_POST[reqemail]'”);
$row = mysql_fetch_array($result);
$pass = $row[‘password’];
$rights = $row[‘useright’];
$name = $row[‘reqfirst’];
$email =$row[‘reqemail’];
IF ($pass != md5($_POST[‘password’])){
(“Incorrect password.”);
header( ‘Location: loginca.php’ ) ;
}
ELSE{
$_SESSION[‘access’]+1;
$
$_SESSION[‘reqfirst’]= $name;
$
header( ‘Location: team_canada.php’ ) ;
}
?>
keep getting an error saying something along the lines of:
Warning: Cannot add header information – headers already sent by (output started at
etc. etc. etc.
Could somebody please tell me what I need to do differently?
[code=php]header( 'Location: loginca.php' ) ;
//snip
header( 'Location: team_canada.php' ) ;[/code]
[code=php]
ob_start();
[/code]
[code=php] and [/code]
[/noparse] tags around your code, which means that it's far harder to spot errors, so I'm gonna wait for that, like I waited for you to do it earlier with your first post.[code=php]<?php
ob_start();
session_start();
include("dbblsr.php");
mysql_select_db("cgowie_teamcanada", $conn);
$result = mysql_query("SELECT * FROM teamcanada WHERE reqemail='$_POST[reqemail]'");
$row = mysql_fetch_array($result);
$pass = $row['password'];
$rights = $row['useright'];
$name = $row['reqfirst'];
$email =$row['reqemail'];
IF ($pass != md5($_POST['password'])){
("Incorrect password.");
header( 'Location: loginca.php' ) ;
}
ELSE{
$_SESSION['access']= $_SESSION['access']+1;
$_SESSION['rights']= $rights;
$_SESSION['reqfirst']= $name;
$_SESSION['reqemail']= $email;
header( 'Location: team_canada.php' ) ;
}
?>
[/code]
[code=php]"reqemail='$_POST[reqemail]'"[/code]
is evaluating as [code=php]"reqemail='Array[reqemail]'"[/code]
since $_POSt is an array, in which case the solution is[code=php]"reqemail='{$_POST[reqemail]}'"[/code]
the braces tell PHP where the variable starts and ends.[code=php]$row = mysql_fetch_array($result);[/code]
since your returning 0 results this means that attempting to fetch the array causes an error. Something I doubt would be the problem, but it might be worth considering something more like:[code=php]if(mysql_num_rows($result)
$row = mysql_fetch_array($result);
else
$row = array();[/code]
since this will avoid errors, although it's not the best error catching it is the simplest.[code=php]$_SESSION['access']= $_SESSION['access']+1;[/code]
$_SESSION['access'] is unset, although I don't have much experience with this myself I can say that it's best to be sure at all times:[code=php]if(isset($_SESSION['access']))
$_SESSION['access']++;
else
$_SESSION['access']=1;[/code]
[code=php]if(mysql_num_rows($result)
$row = mysql_fetch_array($result);
else
$row = array();[/code]
?[code=php]if(mysql_num_rows($result) ) // <-- right here
$row = mysql_fetch_array($result);
else
$row = array();[/code]
[code=php]ob_start();[/code]
to the code and it seems like it is working but as far as i can tell the db is not checked and i dont get to ths portion [code=php]ELSE{
if(isset($_SESSION['access']))
$_SESSION['access']++;
else
$_SESSION['access']=1;
$_SESSION['rights']= $rights;
$_SESSION['reqfirst']= $name;
$_SESSION['reqemail']= $email;
header( 'Location: team_canada.php');
}
?>[/code]
of the code.[code=php]<?php
ob_start();
session_start();
include("dbblsr.php");
mysql_select_db("cgowie_teamcanada", $conn);
$result = mysql_query("SELECT * FROM teamcanada WHERE reqemail='{$_POST[reqemail]}'");
if(mysql_num_rows($result))
$row = mysql_fetch_array($result);
else
$row = array();
print_r($_POST);// show all $_POST values
echo "nn<p>".md5($_POST['password'])."</p>nn";// show MD5 password for comparison with DB
print_r($row);// show DB info
exit;
...
[/code]
then check the names of the variables and such against what your using, if $row is empty then your just not getting any results from the DB. I occasionaly do debuging like this if I can't find a problem, the idea is to list everything that it could possibly be related to, and see if you can spot anything out of the ordinary.[code=html]<form method='post' action='wherever'>[/code]
[code=html]<form method="post" action="checkca.php">[/code]
[code=php]<?php
ob_start();
session_start();
include("dbblsr.php");
$row = array();
mysql_select_db("cgowie_teamcanada", $conn);
$result = mysql_query("SELECT * FROM teamcanada WHERE reqemail='$_POST[reqemail]'");
if(mysql_num_rows($result))
$row = mysql_fetch_array($result);
else
$row = array();
print_r($_POST);// show all $_POST values
echo "nn<p>".md5($_POST['password'])."</p>nn";// show MD5 password for comparison with DB
print_r($row);// show DB info
exit;[/code]
[code=php]<?php
ob_start();
session_start();
include("dbblsr.php");
mysql_select_db("cgowie_teamcanada", $conn);
$result = mysql_query("SELECT * FROM teamcanada WHERE reqemail='$_POST[reqemail]'");
if(mysql_num_rows($result))
$row = mysql_fetch_array($result);
else
$row = array();
$pass = $row['password'];
$rights = $row['useright'];
$name = $row['reqfirst'];
$email =$row['reqemail'];
IF ($pass != md5($_POST['password'])){
("Incorrect password.");
header('Location: loginca.htm');
}
ELSE{
if(isset($_SESSION['access']))
$_SESSION['access']++;
else
$_SESSION['access']=1;
$_SESSION['rights']= $rights;
$_SESSION['reqfirst']= $name;
$_SESSION['reqemail']= $email;
header( 'Location: team_canada.php');
}
?>[/code]
but when i imput the user name and pass I am getting dup [code=html]<form method="post" action="checkca.php">
<div align="center">
<table border="0" width="77%" id="table1" style="border-collapse: collapse">
<tr>
<td width="146"><font face="Arial" size="2"></font></td>
<td width="8"> </td>
<td>Incorrect Email or Password try again</td>
</tr>
<tr>
<td width="146">
<p align="right"><font size="2" face="Arial">Email</font></td>
<td width="8"> </td>
<td><font face="Arial"><input type="text" name="reqemail" size="27"></font></td>
</tr>
<tr>
<td width="146">
<p align="right"><font size="2" face="Arial">Password</font></td>
<td width="8"> </td>
<td><font face="Arial"><input type="password" name="password" size="27"></font></td>
</tr>
<tr>
<td width="146">
<font face="Arial">
<input type="submit" value="Login" name="B1" style="float: right"></font></td>
<td width="8"> </td>
<td><font face="Arial"><input type="reset" value="Reset" name="B2"></font></td>
</tr>
</table>
</div>
</form>[/code]
0.1.9 — BETA 5.19