Jump to content

[SOLVED] mysql_fetch_array error.... headers already sent by my sql statement?!


boo_lolly

Recommended Posts

this is really really weird. I've never encountered an error like this before.

first here's the error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/mysite/functions.php on line 590

Warning: Cannot modify header information - headers already sent by (output started at /var/www/mysite/functions.php:590) in /var/www/dodgecancer/functions.php on line 604

Fatal error: Cannot break/continue 1 level in /var/www/mysite/functions.php on line 605

 

and here's my code:

<?php
            $sql = '
                SELECT
                    *
                FROM
                    bulletins
            ';
            $query = mysql_query($sql) OR die(mysql_error());

            while ($row = mysql_fetch_array($query)) {   #<----- LINE 590
                if ($get_array['ref'] == sha1($row['id'])) {
                    $sql = '
                        DELETE FROM
                            bulletins
                        WHERE
                            id = '. $row['id'] .'
                    ';
                    $query = mysql_query($sql) OR die(mysql_error());
                    if ($query) {
                        add_notification('user_panel', 'green', 'Your bulletin post has been deleted.');
                    }
                }
            }
            header('Location: user_panel.php'); #<-----------------------LINE 604
            break;                                                #<----------------------LINE 605
?>

 

I seriously don't know what to do. I've been trying to test this thing for hours and I cannot understand why it's throwing this error. I've even commented out all processing and just printed the while loop, and everything works... but when I try the above script, it throws the errors. If I can figure out the first error, the other two will go away I'm sure.

 

Here's the weird thing. It gives me this error, right? Then when I press 'Refresh' in the browser, it goes back to the page it's supposed to and shows the correct message. And when I cross reference the database, the correct row has been deleted. So basically, it's working, but throwing an error that doesn't make any sense in the first place... weird right?

 

I need help with this. What's wrong with my syntax or sql statement? Why is it saying there's output when there's clearly NO output?

Link to comment
Share on other sites

ProjectFear,

 

As I mentioned in my previous post, the query is working. I've tested it by simply printing out the contents of each $row. I do not get an error when I do that.

 

I am not sending out any output before the header. I have been looking at this problem for over an hour and I need a fresh set of eyes on this.

 

If my sql statement is wrong, WHAT is wrong with it?

Link to comment
Share on other sites

He is overwriting the $query variable inside of the while loop with a TRUE/FALSE value from the INSERT query, so when the while loop evaluates the condition again, the mysql_fetch_xxxxx instruction fails.

 

THAT WAS IT!!! YOU'RE A GENIOUS BRO!!!!  Thank you SO much!!!!

Link to comment
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.