Jump to content
MakeWebGames

Recommended Posts

Posted

Hello MWG! I need your help today!

I have converted one of my mailbox to V2 - V1. I got some few errors when I try sending a message -

 

Warning: mysql_result() expects parameter 1 to be resource, null given in /home/----/----/mailbox.php on line 371

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/----/----/mailbox.php on line 383

 

Line 371 -

$to=mysql_result($var, 0, 0);($q); 

 

Line 360 - 380

 

$sendto=($_POST['user1']) ? $_POST['user1'] : $_POST['user2'];
{
$q=mysql_query("SELECT userid FROM users WHERE username='{$sendto}'");
if(mysql_num_rows($q)==0)
{
print "You cannot send mail to nonexistant users.<br />
<a href='mailbox.php'>> Back</a>";
$h->endpage();
 	exit;
}
}
$to=mysql_result($var, 0, 0);($q);
if($ir['user_level'] == 1)
       {
       $q_mb=mysql_query("SELECT * FROM mailblock WHERE mb_ADDED=$userid AND mb_ADDER=$to");
               if (mysql_num_rows($q_mb) > 0)
               {
               print "<font color=red><h3>! ERROR</h3>This person has elected <b>NOT</b> to receive mail from you.</font>";
               $h->endpage();
               exit;
               }

 

 

Line 383 -

if (mysql_num_rows($q_mb2) > 0)

 

Line 375 - 393

 

 if (mysql_num_rows($q_mb) > 0)
               {
               print "<font color=red><h3>! ERROR</h3>This person has elected <b>NOT</b> to receive mail from you.</font>";
               $h->endpage();
               exit;
               }
}
$q_mb2=mysql_query("SELECT * FROM mailblock WHERE mb_ADDED=$to AND mb_ADDER=$userid");
               if (mysql_num_rows($q_mb2) > 0)
               {
               print "<font color=red><h3>! ERROR</h3>You have blocked this member so why mail them.</font>";
               $h->endpage();
               exit;
               }
mysql_query("INSERT INTO mail VALUES ('','0',$userid,$to,unix_timestamp(),'$subj','$newmsg',0)");
mysql_query("UPDATE users SET new_mail=new_mail+1 WHERE userid={$to}");
print "Message sent.<br />
<a href='mailbox.php'>> Back</a>";
}

 

Please help me!

Posted (edited)

Where to start with this?

 

I assume there is some validation on the $sendto in your actual script?

 

Something like the following should suffice:

 

if ($_SERVER['REQUEST_METHOD'] == "POST")
{
   $sendto = (array_key_exists('user1', $_POST) && is_string($_POST['user1'])) 
           ? mysql_real_escape_string($_POST['user1']) 
           : mysql_real_escape_string($_POST['user2']);

   if (strlen($sendto) > 0)
   {
       $q = mysql_query("SELECT `userid` FROM `users` WHERE `username` = '{$sendto}'");
       if(mysql_num_rows($q) == 0)
       {
           echo '<p>You cannot send mail to nonexistant users.</p>
           <p><a href="mailbox.php">Go Back</a>';
       }
       else
       {
           $to = mysql_fetch_assoc($r);
           if($ir['user_level'] == 1)
           {
               $q_mb = mysql_query("SELECT * FROM `mailblock` WHERE `mb_ADDED` = '{$ir['userid']}' AND `mb_ADDER` = '{$to['userid']}'");
               if (mysql_num_rows($q_mb) > 0)
               {
                   echo '<p style="color: red;">This person has elected <b>NOT</b> to receive mail from you.</p>';
               }
               else
               {
                   // Send mail here...
               }
           }
       }
   }
}
Edited by Guest
Posted
I don't use mysql_*() but shouldn't you have a connection when using mysql? and I am aware its an error with param 1 but still

You do. You just don't realise it if it's wrapped in a class.

Maybe you should venture into the class files and see what's actually doing? :P

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.   Paste as plain text instead

  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...