150 credits to debug

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
I need someone with php knowledge to debug this:

PHP:
<?
include("includes/rating_config.php");
/*
Dynamic Star Rating Redux
Developed by Jordan Boesch
www.boedesign.com
Licensed under Creative Commons - http://creativecommons.org/licenses/by-nc-nd/2.5/ca/

Used CSS from komodomedia.com.
*/

function getRating($id){

    $total = 0;
    $rows = 0;
    
    $sel = mysql_query("SELECT rating_num FROM ratings WHERE rating_id = '$id'");
    if(mysql_num_rows($sel) > 0){
    
        while($data = mysql_fetch_assoc($sel)){
        
            $total = $total + $data['rating_num'];
            $rows++;
        }
        
        $perc = ($total/$rows) * 20;
        
        //$newPerc = round($perc/5)*5;
        //return $newPerc.'%';
        
        $newPerc = round($perc,2);
        return $newPerc.'%';
    
    } else {
    
        return '0%';
    
    }
}

function outOfFive($id){

    $total = 0;
    $rows = 0;
    
    $sel = mysql_query("SELECT rating_num FROM ratings WHERE rating_id = '$id'");
    if(mysql_num_rows($sel) > 0){
    
        while($data = mysql_fetch_assoc($sel)){
        
            $total = $total + $data['rating_num'];
            $rows++;
        }
        
        $perc = ($total/$rows);
        
        return round($perc,2);
        //return round(($perc*2), 0)/2; // 3.5
    
    } else {
    
        return '0';
    
    }
    
    
}

function getVotes($id){

    $sel = mysql_query("SELECT rating_num FROM ratings WHERE rating_id = '$id'");
    $rows = mysql_num_rows($sel);
    if($rows == 0){
        $votes = '0 Votes';
    }
    else if($rows == 1){
        $votes = '1 Vote';
    } else {
        $votes = $rows.' Votes';
    }
    return $votes;
    
}

function pullRating($id,$show5 = false, $showPerc = false, $showVotes = false, $static = NULL){
    
    // Check if they have already voted...
    $sel = mysql_query("SELECT id FROM ratings WHERE IP = '".$_SERVER['REMOTE_ADDR']."' AND rating_id = '$id'");
    if(mysql_num_rows($sel) > 0 || $static == 'novote' || $_COOKIE['has_voted_'.$id]){
    
        $text = '';
        
        if($show5 || $showPerc || $showVotes){

            $text .= '<div class="rated_text">';
            
        }
            
            if($show5){
                $text .= 'Rated <span id="outOfFive_'.$id.'" class="out5Class">'.outOfFive($id).'</span>/5';
            } 
            if($showPerc){
                $text .= ' (<span id="percentage_'.$id.'" class="percentClass">'.getRating($id).'</span>)';
            }
            if($showVotes){
                $text .= ' (<span id="showvotes_'.$id.'" class="votesClass">'.getVotes($id).'</span>)';
            }
            
        if($show5 || $showPerc || $showVotes){    
            
            $text .= '</div>';
        
        }
        
        
        return $text.'
            <ul class="star-rating2" id="rater_'.$id.'">
                <li class="current-rating" style="width:'.getRating($id).';" id="ul_'.$id.'"></li>
                <li><a onclick="return false;" href="#" title="1 star out of 5" class="one-star" >1</a></li>
                <li><a onclick="return false;" href="#" title="2 stars out of 5" class="two-stars">2</a></li>
                <li><a onclick="return false;" href="#" title="3 stars out of 5" class="three-stars">3</a></li>
                <li><a onclick="return false;" href="#" title="4 stars out of 5" class="four-stars">4</a></li>
                <li><a onclick="return false;" href="#" title="5 stars out of 5" class="five-stars">5</a></li>
            </ul>
            <div id="loading_'.$id.'"></div>';

        
    } else {
        
        if($show5 || $showPerc || $showVotes){
            
            $text .= '<div class="rated_text">';
            
        }
            if($show5){
                $show5bool = 'true';
                $text .= 'Rated <span id="outOfFive_'.$id.'" class="out5Class">'.outOfFive($id).'</span>/5';
            } else {
                $show5bool = 'false';
            }
            if($showPerc){
                $showPercbool = 'true';
                $text .= ' (<span id="percentage_'.$id.'" class="percentClass">'.getRating($id).'</span>)';
            } else {
                $showPercbool = 'false';
            }
            if($showVotes){
                $showVotesbool = 'true';
                $text .= ' (<span id="showvotes_'.$id.'" class="votesClass">'.getVotes($id).'</span>)';
            } else {
                $showVotesbool = 'false';    
            }
            
        if($show5 || $showPerc || $showVotes){    
        
            $text .= '</div>';
            
        }
        
        return $text.'
            <ul class="star-rating" id="rater_'.$id.'">
                <li class="current-rating" style="width:'.getRating($id).';" id="ul_'.$id.'"></li>
                <li><a onclick="rate(\'1\',\''.$id.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$id.'&rating=1" title="1 star out of 5" class="one-star" >1</a></li>
                <li><a onclick="rate(\'2\',\''.$id.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$id.'&rating=2" title="2 stars out of 5" class="two-stars">2</a></li>
                <li><a onclick="rate(\'3\',\''.$id.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$id.'&rating=3" title="3 stars out of 5" class="three-stars">3</a></li>
                <li><a onclick="rate(\'4\',\''.$id.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$id.'&rating=4" title="4 stars out of 5" class="four-stars">4</a></li>
                <li><a onclick="rate(\'5\',\''.$id.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$id.'&rating=5" title="5 stars out of 5" class="five-stars">5</a></li>
            </ul>
            <div id="loading_'.$id.'"></div>';
    
    }
}

// Added in version 1.5
function getTopRated($limit, $table, $idfield, $namefield){
    
    $result = '';
    
    $sql = "SELECT ratings.rating_id,".$table.".".$namefield." as thenamefield,ROUND(AVG(ratings.rating_num),2) as rating 
            FROM ratings,".$table." WHERE ".$table.".".$idfield." = ratings.rating_id GROUP BY rating_id 
            ORDER BY rating DESC LIMIT ".$limit."";
            
    $sel = mysql_query($sql);
    
    $result .= '<ul class="topRatedList">'."\n";
    
    while($data = mysql_fetch_assoc($sel)){
        $result .= '<li>'.$data['thenamefield'].' ('.$data['rating'].')</li>'."\n";
    }
    
    $result .= '</ul>'."\n";
    
    return $result;
    
}
?>

this is the error it gives:
Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/viggeswe/public_html/flash/includes/rating_functions.php on line 183

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/viggeswe/public_html/flash/includes/rating_functions.php on line 183

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/viggeswe/public_html/flash/includes/rating_functions.php on line 187

Code between 183 and 189:

PHP:
	$sel = mysql_query($sql);
	
	$result .= '<ul class="topRatedList">'."\n";
	
	while($data = mysql_fetch_assoc($sel)){
		$result .= '<li>'.$data['thenamefield'].' ('.$data['rating'].')</li>'."\n";
	}
 
Last edited:

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
http://flash.jagf.net

Now the error has changed:
Warning: mysql_query() [function.mysql-query]: Access denied for user 'viggeswe'@'stoli.x10hosting.com' (using password: NO) in /home/viggeswe/public_html/flash/includes/rating_functions.php on line 183

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/viggeswe/public_html/flash/includes/rating_functions.php on line 183

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/viggeswe/public_html/flash/includes/rating_functions.php on line 187
 
Last edited:

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
Warning: mysql_query() [function.mysql-query]: Access denied for user 'viggeswe'@'stoli.x10hosting.com' (using password: NO) in /home/viggeswe/public_html/flash/includes/rating_functions.php on line 183

Its not getting the dbuser/dbpass/dbname from your config file. Perhaps an absolute path may help.
 

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
And how do I do that? Can't I just in some way put in my database info in there so it don't need to load the config file? I got it! The idiot had typed in include("includes/rating_config.php"); instead of include("rating_config.php");.

Still says the same thing. ANd btw, look at the x10 ad under the adsense!
c31a37ba.png
Should it be so? Mhhhh that was a new adsense function lol.
 
Last edited:

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
Echo out $dbuser and see what you get. Chances are its empty.
 

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
How do I do that???

this is the database info I have putted in the config file <?
$server = 'mysql.x10hosting.com';
$dbuser = 'viggeswe_vigswe';
$dbpass = '*my password*';
$dbname = 'viggeswe_phpbb';

$x = mysql_connect($server,$dbuser,$dbpass);
mysql_select_db($dbname,$x);
?>
 
Last edited:

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
PHP:
var_dump($dbuser);
in your index.php or wherever you call the rating script.
 
Last edited:

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
Which means its not getting it.

CHange your include to your full path for the config.

Code:
/home/viggeswe/public_html/flash/includes/rating_config.php

If you don't know how to do that, then I don't know how to help you either =)
 

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
string(15) "viggeswe_vigswe" on index.php
NULL in ratings_function.php
Edit:
But wait. I have another script on that page that uses database. Do that code really take it from the right script now? Because in the ratings_function.php it show NULL
 
Last edited:

supajason

Member
Messages
288
Reaction score
2
Points
18
How do I do that???

this is the database info I have putted in the config file <?
$server = 'mysql.x10hosting.com';
$dbuser = 'viggeswe_vigswe';
$dbpass = '*my password*';
$dbname = 'viggeswe_phpbb';

$x = mysql_connect($server,$dbuser,$dbpass);
mysql_select_db($dbname,$x);
?>

i thought that the server was localhost?
 

supajason

Member
Messages
288
Reaction score
2
Points
18
as a test comment out the include line

and put:

PHP:
$user="";
$pass="";
$host="";
$database="";

$x = mysql_connect($host, $user, $pass) or die(mysql_error());

mysql_select_db($database, $x) or die(mysql_error());

when did they change it? (just found the thread no worries)

have you added stoli to access list?
 
Last edited:

fitzysit

New Member
Messages
69
Reaction score
0
Points
0
all signs point to null connection with your MYSQL server and a bad password, it may not of connected properly but try what supajason said and try that it should work
 
Last edited:

supajason

Member
Messages
288
Reaction score
2
Points
18
Hmmmmmmmm!

ok change it back and try changing:

PHP:
mysql_select_db($dbname,$x);

to

PHP:
@mysql_select_db($dbname,$x);

in the config file.
 
Last edited:
Top