954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

What's going on here?

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=" "; } else $img_s="".stripslashes($row->b_desc).""; $dis[]="".$img_s.""; $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

stp123
Newbie Poster
1 post since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

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.-

chmazur
Light Poster
30 posts since Sep 2007
Reputation Points: 10
Solved Threads: 3
 

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";
ryan_vietnow
Posting Pro
578 posts since Aug 2007
Reputation Points: 28
Solved Threads: 71
 

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.

RoryGren
Junior Poster in Training
60 posts since Oct 2007
Reputation Points: 12
Solved Threads: 8
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You