Jump to content

Shoutbox


harrishcris

Recommended Posts

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");
[b]while ($row = mysql_fetch_row($result)) {[/b]
if ($row[2] != $message) {

Here is my full code...


[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"];

?>[/code]

Any ideas??

Cheers, Chris
Link to comment
Share on other sites

change this:

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

to this

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

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

cheers
Link to comment
Share on other sites

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

What I do to troubleshoot this all the time, is

[code]$q = "select * from some table";
if ($debug) print $q;
[/code]

If I ever want to check some debug information, I just throw a [i]$debug = true[/i] 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!
Link to comment
Share on other sites

[!--quoteo(post=354654:date=Mar 13 2006, 09:03 PM:name=harrishcris)--][div class=\'quotetop\']QUOTE(harrishcris @ Mar 13 2006, 09:03 PM) [snapback]354654[/snapback][/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..
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.