What's going on here?

Reply

Join Date: Nov 2007
Posts: 1
Reputation: stp123 is an unknown quantity at this point 
Solved Threads: 0
stp123 stp123 is offline Offline
Newbie Poster

What's going on here?

 
0
  #1
Nov 4th, 2007
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='clsid27CDB6E-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
Last edited by stp123; Nov 4th, 2007 at 12:07 am. Reason: Original was too long
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 30
Reputation: chmazur is an unknown quantity at this point 
Solved Threads: 3
chmazur's Avatar
chmazur chmazur is offline Offline
Light Poster

Re: What's going on here?

 
0
  #2
Nov 4th, 2007
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.-
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 561
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: What's going on here?

 
0
  #3
Nov 4th, 2007
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:

  1. $hostname="localhost";
  2. $username="user";
  3. $password="pass"
  4. $dbname="database1";
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 60
Reputation: RoryGren is an unknown quantity at this point 
Solved Threads: 8
RoryGren's Avatar
RoryGren RoryGren is offline Offline
Junior Poster in Training

Re: What's going on here?

 
0
  #4
Nov 6th, 2007
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC