Jump to content

Archived

This topic is now archived and is closed to further replies.

joecooper

Warning Errors

Recommended Posts

how can i turn off the warning errors, i get them for "headers allready set" but cant find whats wrong, and it works anyway. just need to make it go from it.

Share this post


Link to post
Share on other sites
"Headers already sent" means you have sent output to the browser [u][b]before[/b][/u] you have called a function like header() or session_start() ect. Eg you might have a space before your headers are being sent, yes it matters.

Don't ignore errors.

Share this post


Link to post
Share on other sites
[!--coloro:#CC0000--][span style=\"color:#CC0000\"][!--/coloro--][!--sizeo:7--][span style=\"font-size:36pt;line-height:100%\"][!--/sizeo--][!--fonto:Courier New--][span style=\"font-family:Courier New\"][!--/fonto--][b]Don't ignore errors.[/b][!--fontc--][/span][!--/fontc--][!--sizec--][/span][!--/sizec--][!--colorc--][/span][!--/colorc--]

PHP was nice enough to tell you about the error, FIX IT. Don't turn it off.

Share this post


Link to post
Share on other sites
If you are getting "headers already sent" errors, your script is [b]NOT[/b] working correctly. Fixing whatever is causeing the problems will make the errors go away.

If you would post your code, we could help you solve the problem.

Ken

Share this post


Link to post
Share on other sites
HI,

I'm also having problems with "headers" and did all the possible solution to fix it but to no avail...here's the Warning: "Warning: Cannot add header information - headers already sent by (output started at /home/virtual/site90/fst/var/www/html/connect.php:17) in /home/virtual/site90/fst/var/www/html/connect.php on line 23"

here's my code:

<?php
$user = "user";
$pass = "pass";
$dbase = "localhost";
$uname = $_POST['user'];
$upass = $_POST['pass'];
$connection = mysql_connect("localhost",$user,$pass)
or die ("Error Connecting to DBase");
mysql_select_db($dbase,$connection)
or die ("Error Connecting to table");
$result = mysql_query("SELECT * FROM usertb",$connection)
or die ("Error querying DBase");
$i = 0;
while($result_ar = mysql_fetch_assoc($result)){
mysql_close();
?>
<?php
ob_start();
if ($upass == $result_ar['upass'] && $uname == $result_ar['uname'])
{
header("Location: clients/myoxy/index.html");
}
else
header("Location: index.html");
?>
<?php
$i+=1;
}
?>

can anyone help me fix this...actually this is working on our network..
Thanks!!!

Share this post


Link to post
Share on other sites
Here is my best guess: I don't know where line 17 is, but I assume it is the line that reads:

[code]
while($result_ar = mysql_fetch_assoc($result)){
[/code]

the problem is you use this a few lines before it:

[code]
$result = mysql_query("SELECT * FROM usertb",$connection)
or die ("Error querying DBase");
[/code]

That causes an error because it doesn't know what $result_ar is, so it can't send headers after that point...

Share this post


Link to post
Share on other sites
[!--quoteo(post=351111:date=Mar 2 2006, 03:21 PM:name=joecooper)--][div class=\'quotetop\']QUOTE(joecooper @ Mar 2 2006, 03:21 PM) [snapback]351111[/snapback][/div][div class=\'quotemain\'][!--quotec--]
does anyone else know how to turn error reporting off?
[/quote]

Hecken is right. Thats definately one you should NOT be ignoring. At least not without detecting and logging it. While you don't want your clients to see error messages, you do not want to ignore them completely.

Use error_reporting() to supress warning and error messages.

Share this post


Link to post
Share on other sites
[!--quoteo(post=352722:date=Mar 8 2006, 11:20 AM:name=AV1611)--][div class=\'quotetop\']QUOTE(AV1611 @ Mar 8 2006, 11:20 AM) [snapback]352722[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Here is my best guess: I don't know where line 17 is, but I assume it is the line that reads:

[code]
while($result_ar = mysql_fetch_assoc($result)){
[/code]

the problem is you use this a few lines before it:

[code]
$result = mysql_query("SELECT * FROM usertb",$connection)
or die ("Error querying DBase");
[/code]

That causes an error because it doesn't know what $result_ar is, so it can't send headers after that point...
[/quote]

can you tell me what should i do...i really need to work this out asap....as i've said before the script works on our local netwok

Thanks

Share this post


Link to post
Share on other sites
[!--quoteo(post=352735:date=Mar 7 2006, 09:50 PM:name=dheon09)--][div class=\'quotetop\']QUOTE(dheon09 @ Mar 7 2006, 09:50 PM) [snapback]352735[/snapback][/div][div class=\'quotemain\'][!--quotec--]
can you tell me what should i do...i really need to work this out asap....as i've said before the script works on our local netwok

Thanks
[/quote]

That $result_ar is fine. It is being initialized and set to the results of the query. If the query was bad, the die() would have been executed and your script would have halted.

Can you show the entire code? And what is being output? There should be output after that warning.

Share this post


Link to post
Share on other sites
[!--quoteo(post=352738:date=Mar 8 2006, 12:00 PM:name=greycap)--][div class=\'quotetop\']QUOTE(greycap @ Mar 8 2006, 12:00 PM) [snapback]352738[/snapback][/div][div class=\'quotemain\'][!--quotec--]
That $result_ar is fine. It is being initialized and set to the results of the query. If the query was bad, the die() would have been executed and your script would have halted.

Can you show the entire code? And what is being output? There should be output after that warning.
[/quote]


If you can see the entire code is posted above, also the Warning...after the warning there was no output...i tried setting a worng pass and user for the connection and it did show the die message so I think the query is good...do you need something else?

Share this post


Link to post
Share on other sites
[!--quoteo(post=352747:date=Mar 7 2006, 10:17 PM:name=dheon09)--][div class=\'quotetop\']QUOTE(dheon09 @ Mar 7 2006, 10:17 PM) [snapback]352747[/snapback][/div][div class=\'quotemain\'][!--quotec--]
If you can see the entire code is posted above, also the Warning...after the warning there was no output...i tried setting a worng pass and user for the connection and it did show the die message so I think the query is good...do you need something else?
[/quote]


Ok, when I remove the clutter of the <? ?> tags, you get this:

[code]

$user = "user";
$pass = "pass";
$dbase = "localhost";
$uname = $_POST['user'];
$upass = $_POST['pass'];

$connection = mysql_connect("localhost",$user,$pass)
or die ("Error Connecting to DBase");

mysql_select_db($dbase,$connection)
or die ("Error Connecting to table");

$result = mysql_query("SELECT * FROM usertb",$connection)
or die ("Error querying DBase");



$i = 0;
while($result_ar = mysql_fetch_assoc($result))
{
   mysql_close();

   ob_start();

   if ($upass == $result_ar['upass'] && $uname == $result_ar['uname'])
   {
      header("Location: clients/myoxy/index.html");
   }
   else
      header("Location: index.html");

   $i+=1;
}

[/code]

I don't really know why youre using an ob_start() (especially without a ob_flush()) and you are also closing your connection multiple times. I'm not sure of the effect on the ob_start() and multiple header() calls, but there is no way that the results you will get from that are what you are actually looking for.

Try something like this:
[code]$found = false;
while ($result_ar = mysql_fetch_assoc($result))
{
   if (($upass == $result_ar['upass']) && ($uname == $result_ar['uname']))
   {
      $found = true;
      break;
   }
}

if ($found) { //valid login
   header("Location: clients/myoxy/index.html");
}
else { //invalid login
   header("Location: index.html");
}
[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=352753:date=Mar 8 2006, 12:27 PM:name=greycap)--][div class=\'quotetop\']QUOTE(greycap @ Mar 8 2006, 12:27 PM) [snapback]352753[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Ok, when I remove the clutter of the <? ?> tags, you get this:

[code]

$user = "user";
$pass = "pass";
$dbase = "localhost";
$uname = $_POST['user'];
$upass = $_POST['pass'];

$connection = mysql_connect("localhost",$user,$pass)
or die ("Error Connecting to DBase");

mysql_select_db($dbase,$connection)
or die ("Error Connecting to table");

$result = mysql_query("SELECT * FROM usertb",$connection)
or die ("Error querying DBase");
$i = 0;
while($result_ar = mysql_fetch_assoc($result))
{
   mysql_close();

   ob_start();

   if ($upass == $result_ar['upass'] && $uname == $result_ar['uname'])
   {
      header("Location: clients/myoxy/index.html");
   }
   else
      header("Location: index.html");

   $i+=1;
}

[/code]

I don't really know why youre using an ob_start() (especially without a ob_flush()) and you are also closing your connection multiple times. I'm not sure of the effect on the ob_start() and multiple header() calls, but there is no way that the results you will get from that are what you are actually looking for.

Try something like this:
[code]$found = false;
while ($result_ar = mysql_fetch_assoc($result))
{
   if (($upass == $result_ar['upass']) && ($uname == $result_ar['uname']))
   {
      $found = true;
      break;
   }
}

if ($found) { //valid login
   header("Location: clients/myoxy/index.html");
}
else { //invalid login
   header("Location: index.html");
}
[/code]
[/quote]

i tried your code and tested it locally but it keeps me directed to "[b]index.html[/b]" even if i used the correct username/password....

Share this post


Link to post
Share on other sites
Grey, All

I stand corrected... I wrote that when I rolled out of bed this morning... Now that I look at it, I was SOOOOO wrong about the $result_ar thing...

Ack!

Looking at what the code actually does, there are far easier ways to accomplish what you are trying to do with that script...

I don't know if a rewrite is an option...

Share this post


Link to post
Share on other sites
[!--quoteo(post=353036:date=Mar 9 2006, 06:12 AM:name=AV1611)--][div class=\'quotetop\']QUOTE(AV1611 @ Mar 9 2006, 06:12 AM) [snapback]353036[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Grey, All

I stand corrected... I wrote that when I rolled out of bed this morning... Now that I look at it, I was SOOOOO wrong about the $result_ar thing...

Ack!

Looking at what the code actually does, there are far easier ways to accomplish what you are trying to do with that script...

I don't know if a rewrite is an option...
[/quote]

Thanks anyway, i did make the code with only 1 <?php .....code......?> and it did work...Thanks for the reminder...

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.