Jump to content

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resourc


runnerjp

Recommended Posts

for some reason i get this error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource for here $lastMessageTime = mysql_num_rows($res) == 1 ? array_shift(mysql_fetch_array($res)) :

 

 

 

i dont understand as all it should be doing is finding if user is flooding :S

 

here is full code

 

<?php
session_start();
require_once '../../settings.php';
include "../../info.php"; // sets username/id ect
$reciever = mysql_real_escape_string($_POST['username']);
$subject = mysql_real_escape_string($_POST['subject']);
$message = mysql_real_escape_string($_POST['message']);
$timestamp = time();

if (!isset($_REQUEST['Submit'])) {
//stop flooding
$query = "SELECT max(`time`) as t FROM messages WHERE receiver='$receiver' AND username='$username'";
$res = mysql_query($query);
$lastMessageTime = mysql_num_rows($res) == 1 ? array_shift(mysql_fetch_array($res)) :
    0;
if ($lastMessageTime > 0 && $lastMessageTime < strtotime('+2 Minutes', $timestamp)) {
    $errors[] = 'Please wait 2 minutes between each message';
}
    //Get their private message count
    $sql = mysql_query("SELECT pm_count FROM users WHERE Username='$reciever'");
    $row = mysql_fetch_array($sql);
    $pm_count = $row['pm_count'];
    //You cant have more than 50 private messages, if they try sending a message to a user with a full inbox return an error message
    if (pm_count >= '1') {
        $errors[] = 'The user you are trying to send a message to has 50 private messages, sorry but we cant send your message untill that user deletes some of their messages.';
    }
//find errors in form
    if ($_POST['subject'] == '' || strlen($_POST['subject']) < 3) {
        $errors[] = 'A subject is required and must contain 3 characters or more';
    }
    if ($_POST['message'] == '' || strlen($_POST['message']) < 3) {
        $errors[] = 'A message is required and must contain 3 characters or more';
    }
    if (is_array($errors)) {
        echo '<p class="error"><b>The following errors occured</b></p>';
        while (list($key, $value) = each($errors)) {
            echo '<span class="error">' . $value . '</span><br />';
        }
    } else {
        //Are the trying to send a message to a real user or to something they just made up?
        $user_check = mysql_query("SELECT * FROM `friends` WHERE `username`= '$username' and friendname = '$reciever' ");
        $user_check = mysql_num_rows($user_check);
        //The user is real and not made up if this is true
        if ($user_check > 0) {
            $pm_count = $pm_count + '1';
            //Update Them
            $userpmupdate = mysql_query("UPDATE users SET pm_count='$pm_count' WHERE username='$reciever'") or
                die(mysql_error());
            ;
            $update = mysql_query("INSERT INTO messages (time,reciever, sender, subject, message) VALUES('$timestamp','$reciever', '$username', '$subject', '$message')") or
                die(mysql_error());
            echo 'Your profile has been update!';
        } else {
            echo 'You may only message friends!';
        }
    }
}
?>

Link to comment
Share on other sites

don't you need a  and time='$t' on the select,

 

or otherwise what it set as $t for?

 

do some error checking as well.

<?php
$query = "SELECT max(`time`) as t FROM messages WHERE receiver='$receiver' AND username='$username'";
$res = mysql_query($query)or dir("select time error".mysql_error());

echo $res;

$lastMessageTime = mysql_num_rows($res) == 1 ? array_shift(mysql_fetch_array($res)) :
    0;

if ($lastMessageTime > 0 && $lastMessageTime < strtotime('+2 Minutes', $timestamp)) {
    $errors[] = 'Please wait 2 minutes between each message';
}
?>

Link to comment
Share on other sites

Are you sure there's column 'username' in messages table?

 

Because this:

$update = mysql_query("INSERT INTO messages (time,reciever, sender, subject, message) VALUES(

 

suggests otherwise.

 

Oh... by the way... receiver is not spelled reciever. That's another error lurking for you. Not to mention you use 'Username' instead of 'username' in

    $sql = mysql_query("SELECT pm_count FROM users WHERE Username='$reciever'"

which might, or might not be wrong. Check it, because MySQL is case sensitive on column names.

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.