Raised This Month: $51 Target: $400
 12% 

Help- error php


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Keros
Member
Join Date: Aug 2013
Old 09-01-2013 , 05:23   Help- error php
Reply With Quote #1

Hello, to make the web Statistics for giving me this error:

Plugin:
https://forums.alliedmods.net/showth...highlight=rank for giving me this error:

Error:



Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\rank\index.php on line 19

My index.php

PHP Code:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<link rel="stylesheet" type="text/css" href="styles.css" />

<script src="js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="js/jquery.titlecase.js"></script>
<script type="text/javascript" src="js/jquery.blockUI.js"></script>
<script src="scripts.js"></script>    
<body onload="make_oddeven(0)">
<?php

include_once "check_restore.php";

global 
$bd_table;
$query1 "SELECT * FROM `$bd_table` ORDER BY score DESC";
$resultado1 $conexao->query($query1);
echo 
"<span style='margin:auto;display:block;text-align:center;color:white;'>Click a player name for detailed statistics.</span><br />";
echo 
"<table id='table1' align='center'><tr><th>POSITION</th><th>NAME</th><th>STEAMID</th><th>SCORE</th><th>KDR</th><th>HEADSHOTS</th><th>ACCURACY</th></td>";
$rank=0;
while (
$row mysql_fetch_array($resultado1)) {
    
$rank++;
    if(
$row['hits'] == 0){
        
$hits 1;
    } else {
        
$hits $row['hits'];
    }
    
    if(
$row['deaths'] == 0){
        
$deaths 1;
    } else {
        
$deaths $row['deaths'];
    }

    if(
$row['shots'] == 0){
        
$shots 1;
    } else {
        
$shots $row['shots'];
    }
    
$accuracy "";
    
    
$temp strval($row['hits']/$shots);
    
//$accuracy = $temp;
    
if(strpos($temp,".") !== false){
        for(
$i 0$i<=strpos($temp,".")+2;$i++){
            if( 
strlen($temp)-<$i ){
                
$accuracy .= "";
            }else{
                
$accuracy $accuracy $temp[$i];
            }
                                                                                
        }
    } else { 
$accuracy $temp ".00";}
    echo 
"<tr align=center onclick=\"showmodal('showplayer.php?id={$row['id']}')\"><td>$rank</td><td>" $row['name'] . "</td><td>{$row['steam']}</td><td>{$row['score']}</td><td>";
    
$temp strval($row['kills']/$deaths);
    if(
strpos($temp,".") !== false){
        for(
$i 0$i<=strpos($temp,".")+2;$i++){
            if( 
strlen($temp)-<$i ){
                break;
            }else{
                echo 
$temp[$i];
            }
            
        }
    } else { echo 
$temp ".00";}
    echo 
"</td><td>{$row['headshots']}</td><td>" $accuracy "</td></tr>";
}
// close connection
$logdb null;
?>
<div id="modal"></div>
What's the problem? thank you very much
Keros is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-01-2013 , 11:24   Re: Help- error php
Reply With Quote #2

Where is $conexao getting its value?
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Keros
Member
Join Date: Aug 2013
Old 09-02-2013 , 02:59   Re: Help- error php
Reply With Quote #3

I do not understand what you mean
Keros is offline
mikehawk
Member
Join Date: Feb 2011
Old 09-02-2013 , 06:17   Re: Help- error php
Reply With Quote #4

I assume the variable $conexao is the db connection info coming from the include file "check_restore.php" . If not, that is the problem! You are not connecting to the database.

It means your Mysql query is failing. You should add error checking to the query. Then when it fails you will get a message telling you details on the MySql error

Change:
PHP Code:
$resultado1 $conexao->query($query1); 
to

PHP Code:
$resultado1 $conexao->query($query1);
if (!
$resultado1) { // add this check.
    
die('Invalid query: ' mysql_error());

(didn't check this code but it should work)

Last edited by mikehawk; 09-02-2013 at 06:21. Reason: add more info
mikehawk is offline
Keros
Member
Join Date: Aug 2013
Old 09-02-2013 , 20:57   Re: Help- error php
Reply With Quote #5

Hello, thank you for the response, it and replaced and is put By His Successfully received file Invalid query: Query was empty
Keros is offline
imdawe
BANNED
Join Date: Aug 2011
Old 09-02-2013 , 21:07   Re: Help- error php
Reply With Quote #6

omg what is this? maybe a code? o.0
Quote:
if( strlen($temp)-1 <$i ){
$accuracy .= ""; <<<<<<<--------------- eh????
}else{
$accuracy = $accuracy . $temp[$i];
}
imdawe is offline
Send a message via MSN to imdawe
Spartan_C001
Senior Member
Join Date: Jul 2013
Old 09-03-2013 , 05:17   Re: Help- error php
Reply With Quote #7

Quote:
Originally Posted by Keros View Post
Hello, thank you for the response, it and replaced and is put By His Successfully received file Invalid query: Query was empty
Means you are submitting a query with nothing in, e.g; ""

Quote:
Originally Posted by imdawe View Post
omg what is this? maybe a code? o.0
Oh look, the query in the code is ""... an empty query!

I'm not sure what the query should be but im guessing you know, i don't work with php or mess with ranks (well, the web interface anyway) so i have no idea :/

Last edited by Spartan_C001; 09-03-2013 at 05:19.
Spartan_C001 is offline
imdawe
BANNED
Join Date: Aug 2011
Old 09-03-2013 , 06:38   Re: Help- error php
Reply With Quote #8

this line $accuracy .= ""; it does nothing. it just attaches a big nothing to a variable.

PHP Code:
if( strlen($temp)->= $i )
{
      
$accuracy  .= $temp[$i];

its pointless, why do you allocate memory for a string, if its unnecessary
PHP Code:
$query1 "SELECT * FROM `$bd_table` ORDER BY score DESC";
$resultado1 $conexao->query($query1); 
can be
PHP Code:
$resultado1 $conexao->query("SELECT * FROM ".$bd_table." ORDER BY score DESC"); 
please show the code where do you initialize this variable: $conexao

Last edited by imdawe; 09-03-2013 at 07:30.
imdawe is offline
Send a message via MSN to imdawe
Keros
Member
Join Date: Aug 2013
Old 09-03-2013 , 11:57   Re: Help- error php
Reply With Quote #9

Hi, I have changed the code that you have given to me, and it still saying Invalid query. There is the code that contains the variable $conexao

PHP Code:
<?php
/* 
=====================================================
                MENSAGENS DE ERRO
=====================================================
*/
$msg[0] = "Conexão com o banco falhou!";
$msg[1] = "Não foi possível selecionar o banco de dados!";
/*
=====================================================
                    CONEXAO
=====================================================
*/
$bd_user ="*****"// DATABASE USER
$bd_password ="*****";// DATABASE PASS
$bd "rankme";// DATABASE
$host ="*****";    // DATABASE HOST


$lastback file_get_contents("up/restore.txt");
    if(
intval($lastback)+180 time()){
        include 
"restore.php";
        
        
file_put_contents("up/restore.txt",time());
    }
// Fazendo a conexão com o servidor MySQL
$conexao = new PDO('sqlite:up/rankme.sq3') or die($msg[0]);
?>

Last edited by Keros; 09-04-2013 at 01:43.
Keros is offline
imdawe
BANNED
Join Date: Aug 2011
Old 09-03-2013 , 13:45   Re: Help- error php
Reply With Quote #10

Don't share password plz.

Modify these lines
PHP Code:
<?php

include_once "check_restore.php";

global 
$bd_table;
$query1 "SELECT * FROM `$bd_table` ORDER BY score DESC";
$resultado1 $conexao->query($query1);
echo 
"<span style='margin:auto;display:block;text-align:center;color:white;'>Click a player name for detailed statistics.</span><br />";
echo 
"<table id='table1' align='center'><tr><th>POSITION</th><th>NAME</th><th>STEAMID</th><th>SCORE</th><th>KDR</th><th>HEADSHOTS</th><th>ACCURACY</th></td>";
$rank=0;
to
PHP Code:
<?php

include_once "check_restore.php";

global 
$bd_table;
var_dump($conexao);
$resultado1 $conexao->query("SELECT * FROM ".$bd_table." ORDER BY score DESC");
if(!
$resultado1)
{
 
print_r($conexao->errorInfo());
 die();
}
echo 
"<span style='margin:auto;display:block;text-align:center;color:white;'>Click a player name for detailed statistics.</span><br />";
echo 
"<table id='table1' align='center'><tr><th>POSITION</th><th>NAME</th><th>STEAMID</th><th>SCORE</th><th>KDR</th><th>HEADSHOTS</th><th>ACCURACY</th></td>";
$rank=0;
And please post result.
imdawe is offline
Send a message via MSN to imdawe
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:55.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode