Jump to content

Recommended Posts

Hi,

So my code returns this:

mysql_query() expects parameter 2 to be resource, null given

 

My query & result is:

$query = "SELECT * FROM wow_logon.accounts WHERE forum_acc = ('$userid')";

$result = mysql_query($query,$connect);

 

So, something's wrong with my connect variable:

$connect = mysql_connect($conf["host"],$conf["user"],$conf["password"]) or die(mysql_error());

                        mysql_select_db($conf["db"],$connect) or die(mysql_error());

 

So I don't get why it doesn't work, perhaps the select db isn't parsed, but it's told which database to use in the query :/

Any help is much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/249147-mysql-link-identifier/
Share on other sites

If this query is inside a function then you need to pass the $connect variable into that function.

 

Also, if you only have one database connection you can do away with $connect entirely, php will just use the open connection for everything.

 

-Dan

Full code:

require("./includes/wow.php");
$userid = $user->data['user_id'];

/**
* This function checks the ban status of the account.
* @return      1 if banned 
*/
function checkBan()
{ 
    $query = "SELECT * FROM wow_logon.accounts WHERE forum_acc = ('$userid')";
    $result = mysql_query($query,$connect);
    if(!$result)
        die(mysql_error());
    $row = mysql_fetch_array($result);
    if($row["banned"] == "1")
    {
        return 1;
        //$ban_reason = $row["banreason"];
    }
           
}

 

Yes, it's inside a function, but what do you mean that i have to pass it?

You either have to pass the variable via function arguments, or register it as a global, or the easiest way is to just take the resource link off of the query

 

Option 1: function foo($id_link) { mysql_query($sql, $id_link); }

 

Option 2: function foo() { global $id_link; mysql_query($sql, $id_link); }

 

Option 3: $result = mysql_query($query); (Of course you do have to have an open connection, but PHP should find the open connection this way.)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.