Hello, just recently I have experience the following error message: "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/ptremail/public_html/admin/newmail.php on line 431"

If anyone could help I would greatly appreciate it. I have pasted the entire code below.

Thanks!

<script language="javascript">
 function clear(){
 for (i=1;i<=240;i++){
  document.getElementById(i).checked=false;
 }
}

 function checkall(){
 for (i=1;i<=240;i++){
  document.getElementById(i).checked=true;
 }
}

function checksearch(){
  clear();
  document.getElementById(225).checked=true; //USA
  document.getElementById(224).checked=true; //UK
  document.getElementById(13).checked=true;  //Australia
  document.getElementById(14).checked=true;  //Austria
  document.getElementById(21).checked=true;  //Belgium
  document.getElementById(39).checked=true;  //Canada
  document.getElementById(59).checked=true;  //Denmark
  document.getElementById(74).checked=true;  //Finland
  document.getElementById(75).checked=true;  //France
  document.getElementById(83).checked=true;  //Germany
  document.getElementById(100).checked=true; //Iceland
  document.getElementById(107).checked=true; //Italy
  document.getElementById(152).checked=true; //Netherlands
  document.getElementById(155).checked=true; //New Zealand
  document.getElementById(195).checked=true; //Spain
}
</script> 
<?
	  if($act=='addemail')  {
	  if(!$lang1)$lang1=0;   if(!$lang2)$lang2=0;   if(!$lang3)$lang3=0;   if(!$lang4)$lang4=0;   if(!$lang5)$lang5=0;   if(!$lang6)$lang6=0;   if(!$lang7)$lang7=0;   if(!$lang8)$lang8=0;   if(!$lang9)$lang9=0;   if(!$lang10)$lang10=0;
	  if($prise)
	  $ma = date("Y-m-d");
	  mysql_query("INSERT INTO reads (furl, fsubject, ftext, fprise, flog, fpass, fsize, fpaytype,senddate) VALUES ('$mailurl', '$subject', '$mailcontent', $prise, '$log', '$pass', $totemails, '$paytype','$ma')") or die('error');
	  $qr= "SELECT MAX(fnum) AS maxid FROM reads";
	  $eredm = mysql_query($qr) or die("error #1");
  	  $adat = mysql_fetch_array($eredm);
	  $curid = $adat['maxid'];
	  extract (mysql_fetch_array(mysql_query("SELECT fnum AS mailnumber  FROM reads WHERE furl='$mailurl' AND fsubject='$subject' AND ftext='$mailcontent'"))) or die('error');
	  $m=0;
	  for ($k=0;$k<=240;$k++){
	  	if (!$fcountry[$k]=="") { 
			$m=$m+1;
			$tomb[$m]=$fcountry[$k]; 
		}
	  }
	  $query = "SELECT * FROM users WHERE (fintarts='$int1' OR fintauto='$int2' OR fintbusiness='$int3' OR fintcomputers='$int4' OR finteducation='$int5' OR fintentertainment='$int6' OR fintfinancial='$int7' OR fintgames='$int8' OR finthealth='$int9' OR finthome='$int10' OR fintinternet='$int11' OR fintintnews='$int12' OR fintmedia='$int13' OR fintrecreation='$int14' OR fintreference='$int15' OR fintsearch='$int16' OR finttechnology='$int17' OR fintsocial='$int18' OR fintsports='$int19' OR finttravel='$int20') AND (lang1=$lang1 OR  lang2=$lang2 OR lang3=$lang3 OR lang4=$lang4 OR lang5=$lang5 OR lang6=$lang6 OR lang7=$lang7 OR lang8=$lang8 OR lang9=$lang9 OR lang10=$lang10) AND  (fincoming BETWEEN $incomingfrom and $incomingto) AND (fgender LIKE '$gender') AND (fage BETWEEN $agefrom and $ageto) AND (accstatus='active')";
	  $query .= " AND (fcountry='$tomb[1]'";
	  for ($j=2;$j<=$m;$j++){
		$query .= " OR fcountry='$tomb[$j]'";
	  }
	  $query .= ")";
	  $sq=mysql_query($query) or die("error");
	  $rows=mysql_num_rows($sq); 
$t=0;
	  if($rows<=$totemails) {$totemails=$rows; $start=0; $step=1;}
	else
{
$ost=$rows%$totemails;
$rows=$rows-$ost;
$step=$rows/$totemails;
$start=rand(0, $step-1);
}
echo"<b>Your e-mail has been sent to following members:</b><br>";
$keres = "SELECT * FROM topbottom";
$eredm = mysql_query($keres) or die("error");
$sor=mysql_fetch_array($eredm);
$toptext = $sor["top"]; $bottext = $sor["bottom"];
$sendto=",";
	  for($i=$start; $i<$rows; $i=$i+$step)
	  	{
$t++;
	  	mysql_data_seek($sq,$i);
		$ar=mysql_fetch_array($sq); extract($ar);
			if(!$prise) 
			{
			$mc="$subject \n $mailcontent ";
			$msubject="$subject - Non paid email from $ptrname";
			}
			else
			{
			$mc="$subject \n $toptext \n $mailcontent \n Click this link to earn  $prise $paytype: \n  $ptrurl/reademail.php?id=$fid&mailcode=$mailnumber \n $bottext";
			$msubject="$subject - Paid email from $ptrname";
			}
		$fr="From: $adminemail\n"."Content-type: text/$mailformat; charset=$mail_coding";
		@mail($femail, $msubject, $mc, $fr );
		$sendto .= $fid.",";
echo("ID: $fid | ");
	  	}
		echo"<hr>$t E_MAILS  HAS BEEN SUCCESSFULLY SENT! ";
	$query = "UPDATE reads SET sendto='$sendto' WHERE fnum='$curid'";
	$eredm = mysql_query($query) or die("error #2");
	  }
	?>
	
	
<table border="0" cellspacing="0" cellpadding="0" bgcolor="f5f5f5" align="center" width="100%">
  <tr>
    <td>
      <form name="form2" method="POST" action="">
        <table border="0" align="left" bgcolor="f5f5f5">
          <tr> 
            <td colspan="2" bgcolor="#006666"><b><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">SEND 
              NEW PAID EMAIL</font></b></td>
          </tr>
          <tr> 
            <td width="77"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Subject:</font></td>
            <td width="299"> 
              <div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
                <input type="text" name="subject" size="50" value="<?if($act=='add') echo$fsubject?>">
                </font></div>
            </td>
          </tr>
          <tr> 
            <td colspan="2"> 
              <div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"></font><font size="2" face="Verdana, Arial, Helvetica, sans-serif">E-mail 
                content:</font></div>
            </td>
          </tr>
          <tr> 
            <td colspan="2"> 
              <div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
                <textarea name="mailcontent" rows="12" cols="50"><?if($act=='add') echo$fcontent?></textarea>
                </font></div>
            </td>
          </tr>
          <tr> 
            <td colspan="2"> <font size="2"> 
              <input type="radio" name="mailformat" value="plain" <? if($act=='add' && $fformat=='text') echo"checked"?>>
              Text format 
              <input type="radio" name="mailformat" value="html" <? if($act=='add' && $fformat=='html') echo"checked"?>>
              HTML format</font></td>
          </tr>
          <tr>
            <td colspan="2">
			
			  <table width="340">
                <tr>
                  <td align="right" class="light" width="147"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Mail 
                    coding: </font></td>
                  <td align="left" class="light" width="181">
                    <select name="mail_coding">
                      <option value="gb2312">Chinese (Simplified)</option><option value="big5">Chinese (Traditional)</option><option value="windows-1250">Czech</option><option value="windows-1250">Dansk</option><option value="windows-1250">Deutsch</option><option value="iso-8859-1">English (GB)</option><option value="windows-1252" selected>English (US)</option><option value="windows-1250">Espa&ntilde;ol</option><option value="windows-1250">Fran&ccedil;ais</option><option value="windows-1250">Magyar</option><option value="windows-1250">Italiano</option><option value="iso-2022-jp">Japanese</option><option value="euc-kr">Korean</option><option value="windows-1250">Nederlands</option><option value="windows-1250">Norsk bokm&aring;l</option><option value="windows-1250">Polski</option><option value="windows-1250">Portugu&ecirc;s</option><option value="windows-1251">Russian (Windows)</option><option value="KOI8-R">Russian (KOI8-R)</option><option value="windows-1250">Slovak</option><option value="windows-1250">Slovenscina</option></select></td>
</tr>
			</table>
			
			
			</td>
          </tr>
          <tr> 
            <td colspan="2"> 
              <div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"></font><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
                <br>
                Link for receive credit for reading this e-mail:<br>
                <input type="text" name="mailurl" size="50" value="<?if($act=='add') echo$furl?>">
                <br>
                </font></div>
            </td>
          </tr>
          <tr bgcolor="#999999"> 
            <td colspan="2"><font color="#FFFFFF"><b><font face="Arial, Helvetica, sans-serif">PAYMENTS</font></b></font></td>
          </tr>
          <tr> 
            <td colspan="2"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Pay 
              for read this e-mail: 
              <input type="text" name="prise" size="3">
              <input type="radio" name="paytype" value="points" checked>
              POINTS 
              <input type="radio" name="paytype" value="usd">
              USD </font></td>
          </tr>
          <tr> 
            <td colspan="2"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">How 
              many e-mails send: 
              <input type="text" name="totemails" size="4">
              </font></td>
          </tr>
          <tr> 
            <td colspan="2"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Advertiser 
              login: 
              <input type="text" name="log">
              </font></td>
          </tr>
          <tr> 
            <td colspan="2"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Advertiser 
              password: 
              <input type="text" name="pass">
              </font></td>
          </tr>
          <tr> 
            <td colspan="2"> 
              <div align="center"> 
                <input type="hidden" name="act" value="addemail">
                <input type="hidden" name="tp" value="newmail">
              </div>
            </td>
          </tr>
        </table>
        <table border="0" align="left" bgcolor="f5f5f5" width="286">
          <tr> 
            <td colspan="2" bgcolor="#999999"><b><font face="Arial, Helvetica, sans-serif" color="#00FF00">FILTRES</font><font face="Arial, Helvetica, sans-serif" color="#FFFFFF"> 
              [check order for setup] </font></b></td>
          </tr>
          <tr> 
            <td colspan="2" bgcolor="dddddd"> 
              <div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b><font face="Arial, Helvetica, sans-serif">By 
                interests:</font></b></font></div>
            </td>
          </tr>
          <tr> 
            <td colspan="2"> 
              <table border="0" cellspacing="5" cellpadding="5" width="100%">
                <tr valign="top"> 
                  <td> <font face="Verdana, Arial, Helvetica, sans-serif" size="2"> 
                    <input type=checkbox name=int1 value="1" checked >
                    Arts<br>
                    <input type=checkbox name=int2 value="1" checked >
                    Automotive<br>
                    <input type=checkbox name=int3 value="1" checked >
                    Business<br>
                    <input type=checkbox name=int4 value="1" checked >
                    Computers<br>
                    <input type=checkbox name=int5 value="1" checked >
                    Education<br>
                    <input type=checkbox name=int6 value=1 checked >
                    Entertainment<br>
                    <input type=checkbox name=int7 value=1 checked >
                    Financial <br>
                    <input type=checkbox name=int8 value=1 checked >
                    Games<br>
                    <input type=checkbox name=int9 value=1 checked >
                    Health<br>
                    <input type=checkbox name=int10 value=1 checked >
                    Home<br>
                    </font></td>
                  <td> <font face="Verdana, Arial, Helvetica, sans-serif" size="2"> 
                    <input type=checkbox name=int11 value=1 checked >
                    Internet<br>
                    <input type=checkbox name=int12 value=1 checked >
                    News<br>
                    <input type=checkbox name=int13 value=1 checked >
                    Media<br>
                    <input type=checkbox name=int14 value=1 checked >
                    Recreation <br>
                    <input type=checkbox name=int15 value=1 checked >
                    Reference<br>
                    <input type=checkbox name=int16 value=1 checked >
                    Search<br>
                    <input type=checkbox name=int17 value=1 checked >
                    Technology<br>
                    <input type=checkbox name=int18 value=1 checked >
                    Social <br>
                    <input type=checkbox name=int19 value=1 checked >
                    Sports<br>
                    <input type=checkbox name=int20 value=1 checked >
                    Travel</font></td>
                </tr>
              </table>
            </td>
          </tr>
          <tr> 
            <td colspan="2" bgcolor="dddddd"> 
              <div align="center"><b><font size="2" face="Arial, Helvetica, sans-serif">By 
                language</font></b></div>
            </td>
          </tr>
          <tr> 
            <td colspan="2"> 
              <table border="0" cellspacing="5" cellpadding="5" width="100%">
                <tr valign="top"> 
                  <td width="54%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2"> 
                    <input type=checkbox name=lang1 value="1" checked >
                    English<br>
                    <input type=checkbox name=lang2 value="1" checked >
                    German<br>
                    <input type=checkbox name=lang3 value="1" checked >
                    France<br>
                    <input type=checkbox name=lang4 value="1" checked >
                    Italian<br>
                    <input type=checkbox name=lang5 value="1" checked >
                    Chinese<br>
                    <br>
                    </font></td>
                  <td width="46%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2"> 
                    <input type=checkbox name=lang6 value=1 checked >
                    Poland<br>
                    <input type=checkbox name=lang7 value=1 checked >
                    Romanian<br>
                    <input type=checkbox name=lang8 value=1 checked >
                    Russian<br>
                    <input type=checkbox name=lang9 value="1" checked >
                    Greece<br>
                    <input type=checkbox name=lang10 value="1" checked >
                    Other</font></td>
                </tr>
              </table>
            </td>
          </tr>
          <tr> 
            <td colspan="2" bgcolor="dddddd"> 
              <div align="center"><b><font size="2" face="Arial, Helvetica, sans-serif">By 
                anual incoming</font></b></div>
            </td>
          </tr>
          <tr> 
            <td colspan="2"> 
              <div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">From 
                $ 
                <input type="text" name="incomingfrom" size="10" value="0">
                to $ 
                <input type="text" name="incomingto" size="10" value="1000000">
                </font> </div>
            </td>
          </tr>
          <tr> 
            <td colspan="2" bgcolor="dddddd"> 
              <div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><b>By 
                gender</b></font></div>
            </td>
          </tr>
          <tr> 
            <td colspan="2"> 
              <div align="center"> 
                <select name="gender">
                  <option value="%">All</option>
                  <option value="Male">Male only</option>
                  <option value="Female">Female only</option>
                </select>
              </div>
            </td>
          </tr>
          <tr> 
            <td colspan="2" bgcolor="dddddd"> 
              <div align="center"><b><font size="2" face="Arial, Helvetica, sans-serif">By 
                age</font></b></div>
            </td>
          </tr>
          <tr> 
            <td colspan="2"> 
              <div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">From 
                <input type="text" name="agefrom" size="5" value="16">
                to 
                <input type="text" name="ageto" size="5" value="90">
                years old</font></div>
            </td>
          </tr>

        </table>
    </td>
  </tr>
<tr>
 <td colspan="2" width="100%" bgcolor="dddddd">
    <div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><b>By countries</b></font></div>
 </td>
</tr>
<tr>
 <?php
   $query = "SELECT * FROM countries";
   $eredm = mysql_query($query) or die("error while opening country database");
   $i=0;
 while ($sor=mysql_fetch_array($eredm)){
   $i=$i+1;
   $curc = $sor["country"];
   if ($i<=60) { $country1.="<input type='checkbox' name='fcountry[]' value='$curc' checked  id='$i'><font face='arial' size='2'>$curc</font><br>\n"; }
   if (($i>60) and ($i<=120)) { $country2.="<input type='checkbox' name='fcountry[]' value='$curc' checked  id='$i'><font face='arial' size='2'>$curc</font><br>\n"; }
   if (($i>120) and ($i<=180)) { $country3.="<input type='checkbox' name='fcountry[]' value='$curc' checked  id='$i'><font face='arial' size='2'>$curc</font><br>\n"; }
   if ($i>180) { $country4.="<input type='checkbox' name='fcountry[]' value='$curc' checked  id='$i'><font face='arial' size='2'>$curc</font><br>\n"; }
 }
 ?>
 <td align="center">
 <table>
  <tr>
   <td width="25%" align="left" valign="top"><?php print($country1); ?></td>
   <td width="25%" align="left" valign="top"><?php print($country2); ?></td>
   <td width="25%" align="left" valign="top"><?php print($country3); ?></td>
   <td width="25%" align="left" valign="top"><?php print($country4); ?></td>
  </tr>
 </table>
   <a href="javascript:clear()">Un-check all countries</a> | <a href="javascript:checkall()">Check all countries</a> 
| <a href="javascript:checksearch()">Check search countries</a>
 </td>
</tr>
<tr> 
  <td colspan="2"> 
   <div align="center"> 
   <p>&nbsp;</p>
   <p>
   <input type="submit" name="Submit3" value="Send e-mail to members">
   </p>
   </div>
  </td>
</tr>
</form>
</table>
<br>
<table width="100%" border="0">
  <tr> 
    <td bgcolor="#006666"><b><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Active 
      e-mail campaigns</font></b></td>
  </tr>
  <tr> 
    <td> 
      <table width=100% border=1 bordercolor=cccccc cellspacing=0>
        <tr> 
          <td width="6%"> 
            <div align="center"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">#</font></b></div>
          </td>
          <td width="43%"> 
            <div align="center"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Url 
              to confirm</font></b></div>
          </td>
          <td width="9%"> 
            <div align="center"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Price</font></b></div>
          </td>
          <td width="27%"> 
            <div align="center"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Subject</font></b></div>
          </td>
          <td width="5%"> 
            <div align="center"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Reads</font></b></div>
          </td>
          <td width="10%"> 
            <div align="center"><b>View</b></div>
          </td>
        </tr>
        <?
	$sql=mysql_query("SELECT * FROM reads ORDER BY fnum");
	$rows=mysql_num_rows($sql);
	for($i=0;$i<$rows;$i++)
	{
	mysql_data_seek($sql,$i);
	$arr=mysql_fetch_array($sql);
	extract($arr);
	$sq=mysql_query("SELECT * FROM signtask WHERE tasknum=$fnum");
	$signups=mysql_num_rows($sq);
	echo"
	<tr><td>$fnum</td><td>$furl</td><td>$fprise $fpaytype</td><td>$fsubject</td><td>$freads</td><td><a href=viewemcamp.php?fnum=$fnum target=blank>view</a></td></tr>
	";
	}
	?>
      </table>
    </td>
  </tr>
</table>
Member Avatar for diafol

I don't fancy your chances of getting somebody to wade through this. I gave up after 5 minutes. Have you isolated sections of the code to see which staements are actually causing the error?

My bet would be here:

$query .= " AND (fcountry='$tomb[1]'";
	  for ($j=2;$j<=$m;$j++){
		$query .= " OR fcountry='$tomb[$j]'";
	  }
	  $query .= ")";
	  $sq=mysql_query($query) or die("error");
	  [B]$rows=mysql_num_rows($sq);[/B]

OR one or both of two instances here:

$sql=mysql_query("SELECT * FROM reads ORDER BY fnum");
	[B]$rows=mysql_num_rows($sql);[/B]
	for($i=0;$i<$rows;$i++)
	{
	mysql_data_seek($sql,$i);
	$arr=mysql_fetch_array($sql);
	extract($arr);
	$sq=mysql_query("SELECT * FROM signtask WHERE tasknum=$fnum");
	[B]$signups=mysql_num_rows($sq);[/B]

It's just odd that the preceding mysql_query commands don't trigger an error.

I could not read the complete code but here is my suggestion:

This error is because your original query (query for which you want to execute mysql_num_rows()) is wrong.

Print that original query and execute it in mysql terminal or sqlyog. Then you will get the exact error.

I could not read the complete code but here is my suggestion:

This error is because your original query (query for which you want to execute mysql_num_rows()) is wrong.

Print that original query and execute it in mysql terminal or sqlyog. Then you will get the exact error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.