Jump to content


Photo

Shoutbox


  • Please log in to reply
6 replies to this topic

#1 harrishcris

harrishcris
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 13 March 2006 - 05:35 PM

Hello, I have this script for processing my shoutbox, however it comes up with this error when i click submit: Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/oltvkwrk/public_html/Changeable/Rightside.php on line 104 and row 104 is:

// button has been submited so processs data
$result = mysql_query("SELECT * FROM shoutbox ORDER BY id DESC LIMIT 1");
while ($row = mysql_fetch_row($result)) {
if ($row[2] != $message) {

Here is my full code...


// Delte shoutbox row if over 100
$result = mysql_query("SELECT * FROM shoutbox");
$max_shouts = 100;
if (mysql_num_rows($result) > $max_shouts){
    while (mysql_num_rows($result) > $max_shouts){
    $get_last_row = mysql_query("SELECT * FROM shoutbox ORDER BY id asc limit 1");
        while ($row = mysql_fetch_row($get_last_row)){
        $delete_row = mysql_query("DELETE FROM shoutbox WHERE id=$row[0]");
        $result = mysql_query("SELECT * FROM shoutbox");
        }
    }
}
    
    ?>
          </span>            <?

if (empty($message)) {
$message = "No message left.";
}

if (empty($name)) {
$name = "Anonymous";
}

if (isset($_POST['submit'])){
// button has been submited so processs data
    $result = mysql_query("SELECT * FROM shoutbox ORDER BY id DESC LIMIT 1");
    while ($row = mysql_fetch_row($result)) {
        if ($row[2] != $message) {
        
// assign the ip
$ip = $_SERVER['REMOTE_ADDR'];

   // inserting it into the shoutbox table which we made in the mysql statements before
$result = mysql_query("INSERT INTO shoutbox (id,name,message,ip) VALUES ('NULL','$name', '$message', '$ip')");
}
}
}
//returning the last 5 messages
$result = mysql_query("SELECT * FROM shoutbox order by id desc limit 10");

//the while loop
while($r=mysql_fetch_array($result))
{        
   //getting each variable from the table
   $id=$r["id"];
   $message=$r["message"];
   $name=$r["name"];

?>

Any ideas??

Cheers, Chris

#2 harrishcris

harrishcris
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 13 March 2006 - 05:59 PM

Also, the shoutbox does actually work, even though the error comes up, it still saves the info to the database...

#3 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 13 March 2006 - 06:51 PM

change this:

$get_last_row = mysql_query("SELECT * FROM shoutbox ORDER BY id asc limit 1");

to this

$get_last_row = mysql_query("SELECT * FROM shoutbox ORDER BY id asc limit 1") or die(mysql_error());

it won't solve your problem, but will tell you what the problem may be. the above line is failing you somewhere

cheers
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#4 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 13 March 2006 - 06:56 PM

It means there's a problem with one of your query's.

What I do to troubleshoot this all the time, is

$q = "select * from some table";
if ($debug) print $q;

If I ever want to check some debug information, I just throw a $debug = true on top of the file somewhere.. and the whole page shows my debug information [=

This is a very quick way to troubleshoot SQL queries and whatnot.. Hope that makes sense [=.. Once you know that all the queries can be run properly with correct data, then you'll know you need to look elsewhere.. like making sure the connection is made and whatnot!

Good luck!

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#5 harrishcris

harrishcris
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 13 March 2006 - 09:03 PM

No, my query is fine... the code works fine and it adds the shout into the database, but it comes up with the error message...

#6 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 13 March 2006 - 11:31 PM

[!--quoteo(post=354654:date=Mar 13 2006, 09:03 PM:name=harrishcris)--][div class=\'quotetop\']QUOTE(harrishcris @ Mar 13 2006, 09:03 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
No, my query is fine... the code works fine and it adds the shout into the database, but it comes up with the error message...
[/quote]

Yep.. normally when everything works fine for me I get an error message as well..

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#7 harrishcris

harrishcris
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 March 2006 - 06:55 PM

So does anyone have a solution or know a different way of achieving what i want to do...???




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users