0

Im a little desperate here, Im not a very experience PHP developer and right now im at work on my own with a problem I cant fix.

I have 30 or 40 websites, on 30 or 40 domains (a site for each country)

all the sites use exactly the same code its identical)

However one of my sites is not showing up. Its just not loading there are no errors it just doesnt load. I've been working on it all day and I believe it is due to a function but I cant see the problem with it.

The header file calls the config file@

<? include('config.php'); ?>

the config file calls the functions file

include('functions.php'); 

and to figure out which function may be the problem I started at the bottom and deleted them one by one refreshing page each time. Eventually I got to a function, that once deleted, my page loaded but obviously with other errors due to missing functions.

the function that I believe is the problem is:

function get_contenttitle($SectionID,$languageid){
global $languageid;
global $mysql_connect;
if($languageid==''){$languageid=$_SESSION["SelectLanguage"];}
$query='SELECT * FROM website.content WHERE SortOrder="'.$SectionID.'" AND LanguageID="'.$languageid.'" AND Active=1 AND LanguageID IN (1, 2, 3, 4, 5, 6, 8, 11, 12, 14, 15, 16, 30)';
//$content=dbqueryintoarray($query);
$content=db_query_into_array_enhanced($mysql_connect,$query);
if(count($content)>0){
    $return=$content[0]["ContentTitle"];
    }else{
    if($languageid==''){$languageid=$_SESSION["SelectLanguage"];}
    $query='SELECT * FROM website.content_auto WHERE SortOrder="'.$SectionID.'" AND LanguageID="'.$languageid.'" AND Active=1 AND LanguageID IN (1, 2, 3, 4, 5, 6, 8, 11, 12, 14, 15, 16, 30)';
    //$content=dbqueryintoarray($query);
    $content=db_query_into_array_enhanced($mysql_connect,$query);
    if(count($content)>0){
        $return=$content[0]["ContentTitle"];
        }else{
        $query='SELECT * FROM website.content WHERE SortOrder="'.$SectionID.'" AND LanguageID="1" AND Active=1';
        //$content=dbqueryintoarray($query);
        $content=db_query_into_array_enhanced($mysql_connect,$query);
        if(count($content)>0){
            $return=$content[0]["ContentTitle"];
            }else{
            $return='<b><font color="#FF0000">Warning:</font></b> Content does not exist';          
            }
        }
    }
$return=str_replace(chr(10),'<br>',$return);
return $return;
}

now this function is called in the top navigation. If I remove the function the page loads down to the navigation where it is called and then obviously stops. as soon as i put the function back in the page stops loading again at all.

This function uses a db_query_into_array_enhanced function which looks like this:

function db_query_into_array_enhanced($mysql_connect,$query){
global $mysql_debug_comments;
global $total_query_count;
global $total_query_time;
global $total_function_time;
global $log_to_firephp;
global $query_results_to_firephp;
global $output_stats_to_browser;
global $firephp;
global $slow_query_time;
global $query_time;

$bt=debug_backtrace();
$file=$bt[1]["file"];
$pos=strrpos($file,'/');
$calling_script=substr($file,($pos+1));
$calling_line=$bt[1]["line"];

settype($retval,"array");

$query_start=getmicrotime();
$result=mysqli_query($mysql_connect,$query);
$query_end=getmicrotime();
$query_time=($query_end-$query_start);
$total_query_time=$total_query_time+$query_time;
$query_time_ms=round($query_time*1000);

if(!$result){$mysql_debug_comments.="<!-- db_query_into_array_enhanced | Called By: ".$calling_script." | Line: ".$calling_line." | Query FAILED ".$query." -->\n\n";}

if($result){
    $success=true;
    $function_start=getmicrotime();
    $row_count=mysqli_num_rows($result);
    for($x=0;$x<$row_count;$x++){$row=mysqli_fetch_array($result,MYSQLI_ASSOC);array_push($retval,$row);}
    mysqli_free_result($result_set);
    $function_end=getmicrotime();
    $function_time=($function_end-$function_start);
    $total_function_time=$total_function_time+$function_time;
    $mysql_debug_comments.="<!-- Function: db_query_into_array_enhanced | Called By: ".$calling_script." | Line: ".$calling_line." | Status: OK | Results: ".count($retval)." rows | Query Time: ".$query_time_ms."ms | Total Time: ".round($total_query_time*1000)." ms ";
    if($query_time_ms>$slow_query_time){$mysql_debug_comments.=" | Query: ".$query." ";}
    $mysql_debug_comments.="-->\n\n";
    $total_query_count++;
    }

if($log_to_firephp==true){
    $query_time_ms=round($query_time*1000);
    $function_time_ms=round($function_time*1000);
    $total_time=$query_time+$function_time;
    $query_perc=round(($query_time/$total_time)*100,2);
    $function_perc=round(($function_time/$total_time)*100,2);
    $log_type='info';
    if($success==true){
        $message1='db_query_into_array_enhanced | Query: "'.$query.'"';
        $message2='db_query_into_array_enhanced | Rows: '.count($retval).' | MySQL Time: '.$query_time_ms.'ms ('.$query_perc.'%) | Function Time: '.$function_time_ms.'ms ('.$function_perc.'%) | Total Time: '.($query_time_ms+$function_time_ms).'ms';
        if(($query_time>0.5) or ($function_time>0.5) or ($query_time+$function_time>0.5)){$log_type='warn';}
        }else{
        $message1='db_query_into_array_enhanced | Query: "'.$query.'" | QUERY FAILED!';
        $log_type='error';
        }
    if($log_type=='info'){$firephp->info($message1);$firephp->info($message2);}
    if($log_type=='warn'){$firephp->warn($message1);$firephp->warn($message2);}
    if($log_type=='error'){$firephp->error($message1);}
    }

if($query_results_to_firephp==true){        
    $headings=array_keys($retval[0]);
    $table=array();
    $table[]=$headings;
    for($r=0;$r<count($retval);$r++){
        $row=array();
        for($c=0;$c<count($retval[0]);$c++){array_push($row,$retval[$r][$headings[$c]]);}
        $table[]=$row;
        }
    $firephp->table('Results from MySQL Query "'.$query.'" Rows: '.count($retval).' Time: '.($query_end-$query_start).'s', $table);
    }

if($output_stats_to_browser==true){
    echo 'Query: '.$query.'<br>';
    echo 'Query Time: '.$query_time_ms.'ms ('.$query_perc.'%)<br>';
    echo 'Function Time: '.$function_time_ms.'ms ('.$function_perc.'%)<br>';
    echo 'Total Time: '.($query_time_ms+$function_time_ms).'ms<br>';
    echo 'Rows returned: '.count($retval).'<br>';
    }

return $retval;
}

Ive checked every single piece of code against one of the other working sites and everything is the same. EXACTLY the same.

im going out of my mind here can someone please please please help me out

much appreciated

  • 2
    Have you tried checking `mysql_error()` – Jared Mar 18 '13 at 16:07
  • What happens if you put `error_reporting(E_ALL);` at the top of the code. What error message is showing? – Hugo Delsing Mar 18 '13 at 16:08
  • if i put error reporting in with the function in place the page still fails to load and I get no errors. If i remove the function I get this. as well as many others Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /var/www/www.lektronix.fr/inc/functions.php on line 82 Notice: Undefined variable: result_set in /var/www/www.lektronix.fr/inc/functions.php on line 84 Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, null given in /var/www/www.lektronix.fr/inc/functions.php on line 84 –  Mar 18 '13 at 16:10
  • 1
    Really bad program design. Avoid `mysql_` functions and `global`s. You should rather try PDO. – ShuklaSannidhya Mar 18 '13 at 16:12
  • to check for mysql error try `mysql_query($query) or die(mysql_error());` – Hugo Delsing Mar 18 '13 at 16:12
  • I dont know what PDO is, and I didnt write this code im just trying to fix it –  Mar 18 '13 at 16:12
  • something strange is that if i remove the function complete the page begins to load, but if i so much as declare the function and leave it completely empty, the page fails to load at all again –  Mar 18 '13 at 16:13
  • So you have already made some debugging efforts, so you should simply continue to debug into the function itself. You code doesn't seem to do a good job of handling edge cases (like what happens when `count($content) === 0`). Likely you are getting an unexpected query result and not handling it well. Also, as a side note, you should really move away from all the `global` references you have. They are going to make you code way more complex. You should really start looking at object-oriented coding. – Mike Brant Mar 18 '13 at 16:15
  • Hopefully once im more experience I can do that but this isnt my code and I dont really understand much of it right now –  Mar 18 '13 at 16:18
  • if someone could even direct me that would be great, dummed down versions only though please :-/ –  Mar 18 '13 at 16:21
  • Something seems to be wrong with your connection to mysql: `Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)` shows up on your page. – Daniel Figueroa Mar 18 '13 at 16:23
  • Hi Daniel, Yes I placed this code in just below the SQL statement........... mysql_query($query) or die(mysql_error()); ........... that is the result of that –  Mar 18 '13 at 16:26
  • Okay well that means just what it said, that it can't connect to mysql, that's probably why you got the first error. I'd check that mysql is running and that you can connect to it, for example by writing a testfile that does a simple query. Best of luck to you, because that is some messy code you got to work with. – Daniel Figueroa Mar 18 '13 at 16:28
  • Yes there is a connection to the database. Just above the navigation is a little pit of text which is also selected from the database and this appears fine –  Mar 18 '13 at 16:35
  • [How to get useful error messages in PHP?](http://stackoverflow.com/q/845021/1409082) – Jocelyn Mar 18 '13 at 16:48

1 Answers1

0

My guess would be that the function "get_contenttitle" is looking for data from a database it is not connected to. and I don't see a connection in that other function "db_query_into_array_enhanced" either. Is there a function for connecting to the database? If so check that out. Make sure THAT is EXACTLY the same as one of the working sites.

  • yes there was another function for connections, you were right the IP address was incorrect, I changed it but nothing happened. I had to search and I found this IP was used throughout the site –  Mar 19 '13 at 14:16