User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,584 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,585 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 680 | Replies: 3
Reply
Join Date: Nov 2007
Posts: 1
Reputation: stp123 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
stp123 stp123 is offline Offline
Newbie Poster

What's going on here?

  #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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Location: Buenos Aires
Posts: 30
Reputation: chmazur is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
chmazur's Avatar
chmazur chmazur is offline Offline
Light Poster

Re: What's going on here?

  #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  
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation: ryan_vietnow is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 68
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: What's going on here?

  #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";
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
Reply With Quote  
Join Date: Oct 2007
Location: South Africa
Posts: 60
Reputation: RoryGren is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
RoryGren's Avatar
RoryGren RoryGren is offline Offline
Junior Poster in Training

Re: What's going on here?

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the PHP Forum

All times are GMT -4. The time now is 6:30 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC