Jump to content

mysql_fetch_array() expects parameter 1 to be resource, boolean


Gu3rr1lla

Recommended Posts

Hey im new to PHP and trying to build a small fantasy football app. I am getting this error:

 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\Users\Jonny\Desktop\projects\xampp\htdocs\phpprojects\elitefifa\home.php on line 23

 

here is the relevant code:

<?php
/**Start session */
session_start();
if (!array_key_exists("user", $_SESSION)) {
    header('Location: index.php');
    exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        require_once("Includes/db.php");

        $teamID = FifaDB::getInstance()->get_team_id_by_name($_SESSION["user"]);
        echo $teamID;
        $result = FifaDB::getInstance()->get_team_name_by_team_id($teamID);
       
       //line 23 below
while($row = mysql_fetch_array($result)){
          $teamName = $row["name"];
          echo $teamName;
        }
        ?>
    </body>
</html>

public function get_team_id_by_name($name){
        $name = mysql_real_escape_string($name);
        $result = mysql_query("SELECT team_id FROM user WHERE name = '" . $name . "'");
        if(mysql_num_rows($result)>0)
            return mysql_result($result, 0);
        else
            return null;
    }

    public function get_team_name_by_team_id($teamID){
        return mysql_query("SELECY * FROM team WHERE id = " . $teamID);
    }

 

Thank you any help, it'll be much appreciated :)

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.