Jump to content

Recommended Posts

[!--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.
Link to comment
https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-13851
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!!!
Link to comment
https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15262
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...
Link to comment
https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15265
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.
Link to comment
https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15269
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
Link to comment
https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15278
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.
Link to comment
https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15281
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?
Link to comment
https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15290
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]
Link to comment
https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15296
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....
Link to comment
https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15308
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...
Link to comment
https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15574
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...
Link to comment
https://forums.phpfreaks.com/topic/3942-warning-errors/#findComment-15639
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.