I get the following error in my code:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in.....line 20
This same thing occurs in lines 28, 54, 55, 108, and 109

I get another error in line 51:
Warning: Cannot modify header information - headers already sent by (output started.....)

Here is the code:

<?
$conn_id;
$sql_res;
$sql_res2;
$sql_query;

$HTTP_REFERER=$_SERVER["HTTP_REFERER"];
$REQUEST_METHOD=$_SERVER["REQUEST_METHOD"];

function sql_connect(){
global $conn_id,$hostname,$username,$password,$dbname;
$conn_id=mysql_connect($hostname,$username,$password);
mysql_select_db($dbname);
}

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]);

I have posted 113 lines of code...just count from the bottom to find lines 108 and 109

Hi! Did you make an echo of your query? Are you sure that this query is OK? The sql_connect function is connecting OK to the database?

ch.-

you have not specified any values in this variables:

function sql_connect(){
global $conn_id,$hostname,$username,$password,$dbname;
$conn_id=mysql_connect($hostname,$username,$password);
mysql_select_db($dbname);
}

for example:

$hostname="localhost";
$username="user";
$password="pass"
$dbname="database1";

For your second error - php is trying to send output to the http server where the page has already been set up... or something along those lines;-)
Wrap your whole page in ob_start() .... ob_end_flush().
What that does is to hold all the php output in its Output Buffer (ob) until it receives the ob_end_flush() command, whereupon it sends all the output together.

http://www.php.net/ob_start and http://www.php.net/manual/en/function.ob-end-flush.php might help.

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.