Could you please help me with boolean?

Discussion in 'PHP' started by liner, Dec 12, 2012.

  1. #1
    Good day! Could you please help me with boolean? I have some old website from another developers and now some problem with boolean error, so here is problem:


    Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in/home/site/public_html/dbfunction.php on line 83


    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in/home/site/public_html/dbfunction.php on line 92


    and


    Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in/home/site/public_html/dbfunction.php on line 121


    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in/home/site/public_html/dbfunction.php on line 129


    Code:


    <?
    
    
    class dbconn_fontpage{
    
    
    	var $dbname = "";
    
    
    	function dbconn_fontpage($host,$user,$pass,$dbname){
    
    
    		if(!mysql_connect($host,$user,$pass)){
    				echo "Database Error!";
    		}
    
    
    		mysql_query("set NAMES utf8");
    		$this->dbname = $dbname;
    
    
    	}
    
    
    	function selected_list_business($str_op){
    
    
    		$str = "";
    
    
    		$sql  = "select * from business ";
    		$sql .= " order by bus_id asc"; 
    
    
    		$result = mysql_db_query($this->dbname,$sql);
    
    
    		$num = mysql_num_rows($result);
    
    
    		if($num != 0){
    
    
    //			$str  = "<select name=\"menu1\"  onchange=\"MM_jumpMenu('parent',this,0)\">";
    			$str  = "<select name=\"menu1\"  onchange=\"MM_jumpMenu('self',this,0)\">";
    			$str .= '<option value="'.$isearchscriptname.'" >'.$str_op.'</option>';
    
    
    			while($rs = mysql_fetch_array($result)){
    
    
    				$namelen = strlen($rs[1]);
    			
    				$tellen = strlen($rs['tel_no']);
    			
    				$tolen = $namelen+$tellen;
    			
    				$tolen = 90 - $tolen;
    
    
    				if($namelen != 0){
    
    
    					$str .= '<option label="'.$rs['c_id'].'" value="show-'.$rs['c_id']."-".$rs[0].'.htm" >'.$rs[1];
    
    
    						for($i = 0 ; $i < $tolen ; $i++){
    
    
    							$str .= "-";
    
    
    						}
    
    
    					$str .= $rs['tel_no'].'</option>';
    
    
    				}			
    
    
    			}
    
    
    			$str .= "</select>";
    
    
    		}
    
    
    		return $str;
    
    
    	}
    
    
    	function selected_list_tbindex($tbname,$str_op,$f){
    
    
    	// This will create the contents of the dropdown list of all categories
    
    
    		$str = "";
    
    
    		$sql = "SELECT cat_id, title
     				FROM category
    				JOIN cat_join_type ON category.cat_id = cat_join_type.cat_join_type where cat_join_type.cat_type_id = '$f'
    				";
    		$sql .= " order by category.cat_id asc"; 
    
    
    		$result = mysql_db_query($this->dbname,$sql);
    
    
    		$num = mysql_num_rows($result);
    
    
    		//if($num != 0){
    
    
    			$str  = "<span style='margin-bttom:7px'>";
    //			$str .= "<select name='".$tbname."' id='".$tbname."'  style=\"width:250px;\" onchange=\"MM_jumpMenu('parent',this,0);\" >";
    			$str .= "<select name='".$tbname."' id='".$tbname."'  style=\"width:250px;\" onchange=\"MM_jumpMenu('self',this,0);\" >";
    			$str .= '<option value="'.$isearchscriptname.'" >'.$str_op.'</option>';
    
    
    			while($rs = mysql_fetch_array($result)){
    
    
    				if($rs[0] == $se){
    					$str .= '<option value="'.$isearchscriptname.'?action=showcat&catid='.$rs[0].'" selected="selected">'.htmlspecialchars($rs[1]).'</option>';
    				}else{
    					$str .= '<option value="'.$isearchscriptname.'?action=showcat&catid='.$rs[0].'">'.htmlspecialchars($rs[1]).'</option>';
    				}
    
    
    			}
    
    
    			$str .= "</select>";
    			$str .= "</span>";
    
    
    		//}
    
    
    		return $str;
    
    
    	}
    
    
    	function selected_list_tbindex_location($tbname,$str_op,$f){
    
    
    	// This will create the contents of the dropdown list of all area/locations
    
    
    		$str = "";
    
    
    		$sql = "select * from location order by name asc ";
    
    
    		$result = mysql_db_query($this->dbname,$sql);
    
    
    		$num = mysql_num_rows($result);
    
    
    		//if($num != 0){
    
    
    //			$str  = "<select id='".$tbname."' style=\"width:250px;\" onchange=\"MM_jumpMenu('parent',this,0);\" >";
    			$str  = "<select id='".$tbname."' style=\"width:250px;\" onchange=\"MM_jumpMenu('self',this,0);\" >";
    			$str .= '<option value="'.$isearchscriptname.'" >'.$str_op.'</option>';
    
    
    			while($rs = mysql_fetch_array($result)){
    
    
    				if($rs[0] == $se){
    					$str .= '<option value="'.$isearchscriptname.'?action=showhot&locid='.$rs[0].'&catid=hotels_resorts" selected="selected">'.$rs[1].'</option>';
    				}else{
    					if($rs[0] != 14){
    						$str .= '<option value="'.$isearchscriptname.'?action=showhot&locid='.$rs[0].'&catid=hotels_resorts">'.$rs[1].'</option>';
    					}
    				}
    
    
    			}
    
    
    			$str .= '<option value="list-'.$f.'-14.htm">All</option>';
    			$str .= "</select>";
    
    
    		//}
    
    
    		return $str;
    
    
    	}
    
    
    	function select_list_name($tbname,$str_op,$name){
    
    
    		$str = "";
    
    
    		$sql = "select * from $tbname";
    
    
    		if($tbname == "category"){
    
    
    			$sql .= " order by title asc";
    
    
    		}
    
    
    		$result = mysql_db_query($this->dbname,$sql);
    
    
    		$num = mysql_num_rows($result);
    
    
    		if($num != 0){
    
    
    			$str  = "<select name='".$name."' style='width:300px' >";
    			$str .= '<option value="0"  >'.$str_op.'</option>';
    
    
    			while($rs = mysql_fetch_array($result)){
    
    
    				$str .= '<option value="'.$rs[0].'">'.$rs[1].'</option>';
    
    
    			}
    
    
    			$str .= "</select>";
    
    
    		}
    
    
    		return $str;
    
    
    	}
    
    
    	function get_max_value($f,$table,$cz){
    
    
    		$sql = "select $f from $table ";
    
    
    		if($cz){
    
    
    			 $sql .= " where ".$cz;
    
    
    		}
    
    
    		$re = mysql_db_query($this->dbname,$sql);
    
    
    		$hit = mysql_fetch_array($re); 
    
    
    		return $hit[0];
    
    
    	 }
    
    
    	 function cmd_insert($sql){
    
    
    		return mysql_db_query($this->dbname,$sql);
    
    
    	} 
    
    
    }
    
    
    ?>
    
    Code (markup):
    Thank you very much!
    Best regards, Helena
     
    liner, Dec 12, 2012 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    The class trying to connect to a database that doesn't exist, or you're using the wrong username or password. Instead of getting a resource (a pointer to the database), you're getting FALSE - the indication that there's an error. Your code is getting that and using it as the parameter for mysql_num_rows(). But that has to be given a pointer to a database, not a boolean (true/false value) like FALSE.

    Check the code that calls dbconn_fontpage for the host, username and password. (You may have to trace the variables in that call back to where they're given values.) One or more of them has the wrong value.
     
    Rukbat, Dec 13, 2012 IP
  3. liner

    liner Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Good day, thank you for your help - so i checked password, username and host - all is correct, so try to fix it, but it still same problem (. If i attach a db file - maybe you can help me with this? i can't find a mistake, 'cause i check and all is ok. Thank you so much!
     
    Last edited: Dec 13, 2012
    liner, Dec 13, 2012 IP
  4. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #4
    The db file won't do anything - someone has to connect to your site (as the owner) and look around - at the database and at the code. It's going to take time, and I don't think that you'll find anyone who actually knows what he's doing who won't want to be paid for his time and effort.
     
    Rukbat, Dec 14, 2012 IP
  5. Deluxious

    Deluxious Greenhorn

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #5
    The script is calling a function called "mysql_db_query" that doesn't seem to be defined (at least not in this script).

    I'm assuming that the developer meant to write "mysql_query". First thing I'd do to is test to see if replacing instances of "mysql_db_query" with "mysql_query" fixes the problem.
     
    Deluxious, Dec 22, 2012 IP
  6. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #6
    mysql_db_query is an internal PHP function (manual page) but it's deprecated (all "mysql_" functions are) so it shouldn't be used. That doesn't mean that it won't work, though.
     
    Rukbat, Dec 22, 2012 IP
  7. Deluxious

    Deluxious Greenhorn

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #7
    Thanks for pointing that out Rukbat - I've been using php with mysql for years and have never seen that function. So yeah - please disregard my reply - it's wrong.

    See Rukbat's original reply - the name of the database is an empty string at the top of the script - and it's not assigned anywhere else. You might just need to put the name of your database schema in there.
     
    Deluxious, Dec 22, 2012 IP