1

i am trying to get data from mysql db using steam login.

database.php

<?php
$link = mysql_connect("localhost", "root", "");
$db_selected = mysql_select_db('3', $link);
mysql_query("SET NAMES utf8");

function fetchinfo($rowname,$tablename,$finder,$findervalue) {
    if($finder == "1") 
        $result = mysql_query("SELECT $rowname 
                                FROM $tablename");
    else 
        $result = mysql_query("SELECT $rowname 
                                FROM $tablename 
                                WHERE `$finder`='$findervalue'");

    $row = mysql_fetch_assoc($result);
    return $row[$rowname];
}
?>

index.php

<?php
@include_once('database.php');
@include_once('steamauth/steamauth.php');
if(!isset($_SESSION["steamid"])) {
    die("0");
}
$user = fetchinfo("steamid");
$steam = $_SESSION["steamid"];
if($user == 0) die("Not found");
    $results = mysql_query("SELECT * 
                            FROM `users` 
                            WHERE `steamid`='$steamid'");
    $row = mysql_num_rows($results);
    echo $row;
?>  


<?php
    if(!isset($_SESSION['steamid'])) {
        echo "<div style='margin: 30px auto; text-align: center;'>Welcome Guest! 
        Please log in!<br>";
        loginbutton();
        echo "</div>";
    }  else {
    include ('steamauth/userInfo.php');
?>  

        <tr>
            <td>$steamprofile['steamid']</td>
            <td><?=$steamprofile['steamid']?></td>
            <td>SteamID64 of the user</td>
        </tr>
        <tr>

<?php
    }    
?>

and my database is only steamid & expiration date. I want to logged users can see when it is going to expire + users that are not in mysql tell them "You are not in db".

Thanks guys hope you help me!

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Miguel
  • 25
  • 7
  • What problems are you experiencing? Also mysql_* functions are deprecated, use mysqli or PDO. – Enstage Jun 14 '17 at 23:49
  • 1
    **Don't** use the **deprecated and insecure** `mysql_*`-functions. They have been deprecated since PHP 5.5 (in 2013) and were completely removed in PHP 7 (in 2015). Use MySQLi or PDO instead. – M. Eriksson Jun 14 '17 at 23:49
  • 1
    Don't suppress errors using `@`. (like `@include ...`) How would you ever find out what the error is if you suppress the error messages? – M. Eriksson Jun 14 '17 at 23:51
  • I don't see any `session_start()` before you're using the `$_SESSION`-super global. – M. Eriksson Jun 14 '17 at 23:54
  • **Please** look at your `fetchinfo()` function and its REQUIRED Parameters !!!! But you call it using only ONE Parameter ???? – RiggsFolly Jun 14 '17 at 23:56
  • 1
    Add [error reporting](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php/845025#845025) to the top of your file(s) _while testing_ right after your opening PHP tag for example ` – RiggsFolly Jun 14 '17 at 23:56
  • @RiggsFolly - I would think so. Deleted my comment though. You bet me to it :-) – M. Eriksson Jun 14 '17 at 23:58
  • "Warning: Missing argument 3 for fetchinfo()," "Warning: mysql_fetch_assoc() expects parameter 1 to be resource, " – Miguel Jun 15 '17 at 00:00
  • 1
    Oh.. here's another one: `$steamprofile['steamid']`. That will literally print out the text `$steamprofile['steamid']`, not the contents of that variable. There's simply way too many issues here... – M. Eriksson Jun 15 '17 at 00:00
  • 1
    Your function prototype has 4 **required** parameters `fetchinfo($rowname,$tablename,$finder,$findervalue)` but when you call it `$user = fetchinfo("steamid");` you pass only one. The call must generate a compile error and the query MUST FAIL if the code were ever to get that far – RiggsFolly Jun 15 '17 at 00:02
  • Also as `$finder` is used as a column name in the second query, testing it for `if($finder == "1")` **makes absolutely no sense at all** – RiggsFolly Jun 15 '17 at 00:04

0 Answers0