runnerjp Posted April 4, 2009 Share Posted April 4, 2009 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!'; } } } ?> Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted April 4, 2009 Share Posted April 4, 2009 do a print_r on $res or echo the query out and paste it into your MySQL client. $query = "SELECT max(`time`) as t FROM messages WHERE receiver='$receiver' AND username='$username'"; $res = mysql_query($query); print_r($res); to make sure that everything with the query went fine. Quote Link to comment Share on other sites More sharing options...
revraz Posted April 4, 2009 Share Posted April 4, 2009 Use mysql_error() after your query to see why your query is failing. Quote Link to comment Share on other sites More sharing options...
redarrow Posted April 4, 2009 Share Posted April 4, 2009 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'; } ?> Quote Link to comment Share on other sites More sharing options...
Mchl Posted April 4, 2009 Share Posted April 4, 2009 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.