corrossive Posted March 23, 2009 Share Posted March 23, 2009 I am a new Programmer. Please help me solve my Query. I get the following error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in on line 1.42,50,72,80. The code is <?/* */ $conn_id; $sql_res; $sql_res2; $sql_query; $HTTP_REFERER=$_SERVER["HTTP_REFERER"]; $REQUEST_METHOD=$_SERVER["REQUEST_METHOD"]; function sql_connect(){ global $conn_id,$sql_host,$sql_user,$sql_pass,$sql_db; $conn_id=mysql_connect($sql_host,$sql_user,$sql_pass); mysql_select_db($sql_db); } function sql_execute($sql_query,$wtr){ global $conn_id; $sql_res=mysql_query($sql_query,$conn_id); if($wtr=='get'){ if(mysql_num_rows($sql_res)){ return mysql_fetch_object($sql_res); } else { return ''; } } elseif($wtr=='num'){ return mysql_num_rows($sql_res); } elseif($wtr=='res'){ return $sql_res; } } function sql_rows($id,$table){ global $conn_id; $query="select $id from $table"; $result=mysql_query($query,$conn_id); $number=mysql_num_rows($result); return $number; } function sql_close(){ global $conn_id; mysql_close($conn_id); } function h_banners() { global $cookie_url,$main_url; $sql="select * from banners where b_blk='N' and b_typ='H' and b_exp='N'"; $res=mysql_query($sql); $dis=array(); $dis_id=array(); $num=mysql_num_rows($res); if(mysql_num_rows($res)) { while($row=mysql_fetch_object($res)) { $tmp=explode(".",$row->b_img); $tmp_count=count($tmp); $ext=strtolower($tmp[$tmp_count-1]); if($ext=="swf") { $img_s="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='420' height='60'> <param name='movie' value='".$main_url."/".$row->b_img."'> <param name='quality' value='high'> <embed src='".$main_url."/".$row->b_img."' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='420' height='60'></embed></object>"; } else $img_s="<img src='".$main_url."/".$row->b_img."' border='0' width='420' height='60' alt='".stripslashes($row->b_desc)."' ismap>"; $dis[]="<A href='".$main_url."/banners/index.php?url=".$row->b_url."&seid=".$row->b_id."&sess=set' target='_blank'>".$img_s."</a>"; $dis_id[]=$row->b_id; } $tak=rand(0,$num); $sql_query="select * from banners where b_id='$dis_id[$tak]'"; $num=sql_execute($sql_query,'num'); if($num!=0) { $bann=sql_execute($sql_query,'get'); $d_f=date("d",$bann->b_f_day); $m_f=date("m",$bann->b_f_day); $y_f=date("Y",$bann->b_f_day); $d_t=date("d",$bann->b_t_day); $m_t=date("m",$bann->b_t_day); $y_t=date("Y",$bann->b_t_day); // $f_day=mktime(0,0,0,$m_f,$d_f,$y_f); // $t_day=mktime(0,0,0,$m_t,$d_t,$y_t); $f_day=mktime(0,0,0,$m_f,$d_f,$y_f); $t_day=mktime(0,0,0,$m_t,$d_t,$y_t); $today=mktime(0,0,0,date("m"),date("d"),date("Y")); if(($bann->b_dur=="D") and ($today>$t_day)) { delete_banner($dis_id[$tak]); } elseif($bann->b_dur=="C" and ($bann->b_ncl<=$bann->b_clks)) { delete_banner($dis_id[$tak]); } elseif($bann->b_dur=="I" and ($bann->b_noi<=$bann->b_see)) { delete_banner($dis_id[$tak]); } echo $dis[$tak]; for($i=0; $i<=$ip_co; $i++) { mysql_query("update banners set b_see=b_see+1 where b_id='$dis_id[$tak]'"); } } } } function f_banners() { global $cookie_url,$main_url; $sql="select * from banners where b_blk='N' and b_typ='F' and b_exp='N'"; $res=mysql_query($sql); $dis=array(); $dis_id=array(); $num=mysql_num_rows($res); if(mysql_num_rows($res)) { while($row=mysql_fetch_object($res)) { $tmp=explode(".",$row->b_img); $tmp_count=count($tmp); $ext=strtolower($tmp[$tmp_count-1]); if($ext=="swf") { $img_s="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='720' height='60'> <param name='movie' value='".$main_url."/".$row->b_img."'> <param name='quality' value='high'> <param name='wmode' value='opaque'> <param name='loop' value='false'> <embed src='".$main_url."/".$row->b_img."' loop='false' wmode='opaque' quality='high' swLiveConnect='false' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='720' height='60'></embed></object>"; } else $img_s="<img src='".$main_url."/".$row->b_img."' border='0' width='720' height='60' alt='".stripslashes($row->b_desc)."' ismap>"; $dis[]="<A href='".$main_url."/banners/index.php?url=".$row->b_url."&seid=".$row->b_id."&sess=set' target='_blank'>".$img_s."</a>"; $dis_id[]=$row->b_id; } $tak=rand(0,$num); $sql_query="select * from banners where b_id='$dis_id[$tak]'"; $num=sql_execute($sql_query,'num'); if($num!=0) { $bann=sql_execute($sql_query,'get'); $d_f=date("d",$bann->b_f_day); $m_f=date("m",$bann->b_f_day); $y_f=date("Y",$bann->b_f_day); $d_t=date("d",$bann->b_t_day); $m_t=date("m",$bann->b_t_day); $y_t=date("Y",$bann->b_t_day); // $f_day=mktime(0,0,0,$m_f,$d_f,$y_f); // $t_day=mktime(0,0,0,$m_t,$d_t,$y_t); // $today=mktime(0,0,0,date("m"),date("d"),date("Y")); $f_day=mktime(0,0,0,$m_f,$d_f,$y_f); $t_day=mktime(0,0,0,$m_t,$d_t,$y_t); $today=mktime(0,0,0,date("m"),date("d"),date("Y")); if(($bann->b_dur=="D") and ($today>$t_day)) { delete_banner($dis_id[$tak]); } elseif($bann->b_dur=="C" and ($bann->b_ncl<=$bann->b_clks)) { delete_banner($dis_id[$tak]); } elseif($bann->b_dur=="I" and ($bann->b_noi<=$bann->b_see)) { delete_banner($dis_id[$tak]); } echo $dis[$tak]; for($i=0; $i<=$ip_co; $i++) { mysql_query("update banners set b_see=b_see+1 where b_id='$dis_id[$tak]'"); } } } } function mailing($to,$name,$from,$subj,$body) { global $SERVER_NAME; $subj=nl2br($subj); $body=nl2br($body); $recipient = $to; $headers = "From: " . "$name" . "<" . "$from" . ">\n"; $headers .= "X-Sender: <" . "$to" . ">\n"; $headers .= "Return-Path: <" . "$to" . ">\n"; $headers .= "Error-To: <" . "$to" . ">\n"; $headers .= "Content-Type: text/html\n"; mail("$recipient","$subj","$body","$headers"); } function form_get($value){ global $HTTP_POST_VARS,$HTTP_GET_VARS,$_SERVER; $REQUEST_METHOD=$_SERVER["REQUEST_METHOD"]; if($REQUEST_METHOD=='POST'){ $get_value=$HTTP_POST_VARS["$value"]; } elseif($REQUEST_METHOD=='GET'){ $get_value=$HTTP_GET_VARS["$value"]; } return $get_value; } function cookie_get($name){ global $HTTP_COOKIE_VARS; return $HTTP_COOKIE_VARS[$name]; } //require file, depending on mode function check($mode){ global $cookie_url,$main_url; if(isset($mode)){ $document=$mode.".php"; } else{ $document="main.php"; } require("$document"); } //require admin file, depending on mode function ad_check($mode){ if(isset($mode)){ $document=$mode.".php"; } else{ $document="main.php"; } require("admin/$document"); } //require calendar file, depending on mode function cal_check($mode){ if(isset($mode)){ $document=$mode.".php"; } else{ $document="calendar.php"; } require("calendar/$document"); } //printing java code for listing categories function listing_cats_java($mod){ $sql_query="select * from categories"; $res=sql_execute($sql_query,'res'); while($cat=mysql_fetch_object($res)){ if($mod==1){ echo "; listCategory.setDefaultOption('$cat->cat_id','$cat->cat_id'); listCategory.addOptions('$cat->cat_id','Select Subcategory','$cat->cat_id'"; } elseif($mod==2){ $nex=$cat->cat_id+1; echo " listmessage_categoryId.setDefaultOption('$cat->cat_id','$nex'); listmessage_categoryId.addOptions('$cat->cat_id'"; } $sql_query="select * from sub_categories where cat_id='$cat->cat_id'"; $res2=sql_execute($sql_query,'res'); while($sub=mysql_fetch_object($res2)){ echo ",'$sub->name','$sub->sub_cat_id'"; }//while echo ");"; }//while }//function // Returnds the curent page number on a multipage display function getpage(){ if(!isset($_GET['page'])) $page=1; else $page=$_GET['page']; return $page; } function getpages(){ if(!isset($_GET['page'])) $page=1; else $page=$_GET['page']; return $page; } //Displays the page numbers function show_page_nos($sql,$url,$lines,$page){ $tmp =explode("LIMIT",$sql); if(count($tmp)<1) $tmp =explode("limit",$sql); $pgsql =$tmp[0]; include 'show_pagenos.php'; } //Formats The Date function format_date($date,$time=0){ $tmp =explode(" ",$date); $date2 =explode("-",$tmp[0]); $date =$date2[1]."-".$date2[2]."-".$date2[0]; if($time) return $date." ".$tmp[1]; else return $date; } //just printing listing cats list function listing_cats($sel){ $sql_query="select * from categories"; $res=sql_execute($sql_query,'res'); while($cat=mysql_fetch_object($res)){ if($cat->cat_id=="$sel"){ echo "<option selected value='$cat->cat_id'>$cat->name"; } else{ echo "<option value='$cat->cat_id'>$cat->name"; } }//while }//function //just printing events cats list function events_cats($sel){ $sql_query="select * from event_cat"; $res=sql_execute($sql_query,'res'); while($cat=mysql_fetch_object($res)){ if($cat->cat_id=="$sel"){ echo "<option selected value='$cat->event_id'>".stripslashes($cat->event_nam)."</option>"; } else{ echo "<option value='$cat->event_id'>".stripslashes($cat->event_nam)."</option>"; } }//while }//function //admin header function show_ad_header($adsess){ $mode=form_get("mode"); $act=form_get("act"); ?> <html> <head> <title>Site Administration</title> <link href="styles/style.css" type="text/css" rel="stylesheet"> <? if(($mode='listings_manager')&&($act=='edit')) {?> <script language="Javascript" src="DynamicOptionList.js"></script> <SCRIPT LANGUAGE="JavaScript"> var listCategory = new DynamicOptionList("Category","RootCategory"); <? listing_cats_java(1); ?> listCategory.addOptions('','Select Subcategory',''); listCategory.setDefaultOption('',''); function init() { var theform = document.forms["searchListing"]; listCategory.init(theform); } </SCRIPT> <body marginwidth="5" bgcolor="#ffffff" leftmargin ="5" topmargin="5" marginheight="5" onLoad="listCategory.init(document.forms['searchListing']);"> <? } ?> </head> <body topmargin=2 leftmargin=2> <table width="740"> <tr><td width=100%> <? require('templates/ad_header.php'); ?> </td> <tr><td width=100%> <? }//function //showing header function show_header(){ ?> <html> <head> <title>Demo Site</title> <link href="styles/style.css" type="text/css" rel="stylesheet"> <? $mode=form_get("mode"); $act=form_get("act"); if($mode=="user"){ ?> <script language="JavaScript"> <!-- function formsubmit(type){ document.profile.redir.value=type; document.profile.submit(); } --> </script> <? } elseif(($mode=='listing')&&($act=='create')){ ?> <script language="Javascript" src="DynamicOptionList.js"></script> <SCRIPT LANGUAGE="JavaScript"> var listmessage_categoryId = new DynamicOptionList("message_categoryId","message_rootCategoryId"); <? listing_cats_java(2); ?> listmessage_categoryId.addOptions('8000','computer','8001','creative','8002','erotic','8003','event','8004','household','8005','garden / labor / haul','8006','lessons','8007','looking for','8008','skilled trade','8009','sm biz ads','8010','therapeutic','8011'); function init() { var theform = document.forms["manageListing"]; listmessage_categoryId.init(theform); } </SCRIPT> <body marginwidth="5" bgcolor="#ffffff" leftmargin ="5" topmargin="5" marginheight="5" onLoad="listmessage_categoryId.init(document.forms['manageListing']);"> <? } elseif((($mode=='listing')&&($act!='create')&&($act!='show')&&($act!='feedback'))||(($mode=='search')&&($act=='listing'))){ ?> <script language="Javascript" src="DynamicOptionList.js"></script> <SCRIPT LANGUAGE="JavaScript"> var listCategory = new DynamicOptionList("Category","RootCategory"); <? listing_cats_java(1); ?> listCategory.addOptions('','Select Subcategory',''); listCategory.setDefaultOption('',''); function init() { var theform = document.forms["searchListing"]; listCategory.init(theform); } </SCRIPT> <body marginwidth="5" bgcolor="#ffffff" leftmargin ="5" topmargin="5" marginheight="5" onLoad="listCategory.init(document.forms['searchListing']);"> <? }//elseif ?> </head> <body topmargin=2 leftmargin=2> <table width="740"> <tr><td width=100%> <? require('templates/header.php'); ?> </td> <tr><td width=100%> <? } //showing footer function show_footer(){ ?> </td> <tr><td width=100%> <? require("templates/footer.php"); ?> </td></body></html> <? sql_close(); } //redirect function show_screen($loc){ Header("Location: $loc"); exit; } //error reports function error_screen($errid){ $sql_query="select * from errors where err_id='$errid'"; $err=sql_execute($sql_query,'get'); $error_line=$err->error; $detailes_line=$err->detailes; show_header(); require('error.php'); show_footer(); exit(); } //complete pages function complete_screen($comid){ $sql_query="select * from complete where cmp_id='$comid'"; $cmp=sql_execute($sql_query,'get'); $header_line=$cmp->complete; $detailes_line=$cmp->detailes; show_header(); require('complete.php'); show_footer(); exit(); } //checkin user login info function login_test($mem_id,$mem_pass){ $sql_query="select password,ban from members where mem_id='$mem_id'"; $num=sql_execute($sql_query,'num'); $mem=sql_execute($sql_query,'get'); //if password incorrect Quote Link to comment https://forums.phpfreaks.com/topic/150690-please-help-solve-my-query/ Share on other sites More sharing options...
kickstart Posted March 23, 2009 Share Posted March 23, 2009 Hi I presume that is only part of the listing (lots of functions there that do not appear to be called). However you do not appear to do any check on the returns from the SQL calls before trying mysql_num_rows. As it relies on a valid resource, if the previous select hasn't returned a valid resource then it will fail. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/150690-please-help-solve-my-query/#findComment-791630 Share on other sites More sharing options...
fenway Posted March 27, 2009 Share Posted March 27, 2009 Don't *ever* post entire code blocks like that -- totally useless. You're new, so I guess you didn't know. Consider yourself warned. That error means there was something wrong with the query -- if you echo your query, and post it here, it should be obvious. Quote Link to comment https://forums.phpfreaks.com/topic/150690-please-help-solve-my-query/#findComment-795278 Share on other sites More sharing options...
Maq Posted March 27, 2009 Share Posted March 27, 2009 There's like 7 mysql_num_row() function calls, which line does the error refer to? Like kickstart mentioned, it relies on a valid resource which you apparently do not provide. Try adding an or die statement after your mysql_query call to see if it's throwing any errors. i.e. $sql_res=mysql_query($sql_query,$conn_id) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/150690-please-help-solve-my-query/#findComment-795290 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.