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

mysql / php thing


Post New Thread Reply   
 
Thread Tools Display Modes
shauli
Member
Join Date: Jun 2018
Old 08-14-2018 , 17:14   Re: mysql / php thing
Reply With Quote #11

Quote:
Originally Posted by JocAnis View Post
i think i understood what you said, but as i said, with that code, chrome is showing me everything with no problems, but in-game it wont show the same...what code should i post?

is this enough:

Code:
<?php
$con=mysqli_connect("localhost","root","","statistic");
$map_name = $_GET['map'];
$sql="SELECT name, time, date FROM rezultati JOIN players ON players .id=rezultati.id WHERE map=$map_name AND time ORDER BY time ASC LIMIT 15 ";
$records=mysqli_query($con,$sql);
?>
<html>
...style, table code...

<?php
while($st=mysqli_fetch_assoc($records))
{
$i=1;
echo "<tr align=center >";
echo "<td>".$i."</td>";
echo "<td>".$st['name']."</td>";
 echo "<td >".$st['time']."</td>";
  echo "<td>".substr($dr['date'], 0, -8)."</td>";
echo "</tr>";
$i=$i++;
}
?>
</table>
</head>
</body>
</html>
the site is like from above: blablabla.com/recs.php?map=dd2
Are you sure you're on the right address in the in-game MOTD? Right click the MOTD and select "Copy Link Address" and then past it on Chrome to make sure it's the right address. Maybe you forgot to add "?map=mapname" in your plugin.
shauli is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-14-2018 , 17:18   Re: mysql / php thing
Reply With Quote #12

In your previous posts the error contained mysql_fetch_array yet there isn't a single call of that function in the provided code. Stop omitting important parts.
If you are passing $records to that function call as well it may be happen that $records is FALSE because the query failed. Read the documentation and check for possible errors.
Also don't just plainly assign user-provided data to a query, your code is an easy target for SQL Injection as is. Use prepared statements.
__________________
klippy is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 08-14-2018 , 19:21   Re: mysql / php thing
Reply With Quote #13

@shauli, thanks for trying to help. i figuried out what was the problem and you reminded me to look at that part...its in the sma...
was:
Code:
http://localhost/recs.php?map==%s
now its working (so anyone if has the same prob lul)
Code:
http://localhost/recs.php?map=%s
and im very happy it is working...and its interesting, i drunk fixed it, but sober couldnt lol

@klipica, sry, i couldnt copy ingame error so maybe i wrote it bad...instead of mysql_fetch_array it was: mysqli_fetch_assoc...nije bila namera da skrivam nista, ne zezaj thanks for that sql injection alert, gonna see what is and try to fix it somehow
JocAnis is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 08-14-2018 , 19:30   Re: mysql / php thing
Reply With Quote #14

Try this:
PHP Code:
<?php
define
('DBHOST''localhost');
define('DBUSER''');
define('DBPASS''');
define('DBNAME''');

$dbcon = new mysqli(DBHOSTDBUSERDBPASSDBNAME); 
if(
$dbcon->connect_errno) {
    echo 
"Error connecting to db "$dbcon->connect_errno.""
}

if (!
$dbcon->set_charset("utf8")) {
    
printf("Error loading character set utf8: %s\n"$dbcon->error);
    exit();
}

$map_name $_GET['map'];
$query $dbcon->prepare("SELECT `name`, `time`, `date` FROM rezultati JOIN players ON `players.id` = `rezultati.id` WHERE map = ? AND `time` ORDER BY `time` ASC LIMIT 15"); //AND `time` = ????? something's missing here
$query->bind_param("s"$map_name);
$query->execute();


?>
<html>
<body>
    <table>
    <?php
    
while($result $query->fetch_assoc())
    {
        
$i++;
        echo 
        
"
        <tr style='text-align: center'>
            <td>"
.$i."</td>
            <td>"
.$result['name']."</td>
            <td>"
.$result['time']."</td>
            <td>"
.substr($result['date'], 0, -8)."</td>
        </tr>
        "
;
    }
    
?>
    </table>
</head>
</body>
</html>
Not Tested.
Airkish is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 08-14-2018 , 19:42   Re: mysql / php thing
Reply With Quote #15

@Airkish, i apreciate your help, but i said in my previously post, it was my bad in .sma for linking the url...its all ok now
JocAnis is offline
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 09:40.


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