Jump to content

Recommended Posts

I've spent the last hour and a half trying to figure out what I'm doing wrong by looking through various forums without any luck.

 

Basically, I'm getting this wonderful error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

 

I originally had a string with a bunch of variables in it and thought that was the problem.  So I just hard coded a MySQL query that works in the Starfields, Inc. SQL tab.

 

SELECT `Noxxia9`.`UserData`.* FROM `Users` INNER JOIN `UserData` ON `Users`.`UserId` = `UserData`.`UserId` AND `Users`.`Username` = 'flipsIX'

 

This produces the proper result I'm looking for, So I then put that into my php function, knowing that obviously without variables it won't function correctly, but at least I shouldn't get the error because I won't be returning an empty result.

 

$queryString = "SELECT `Noxxia9`.`UserData`.* FROM `Users` INNER JOIN `UserData` ON `Users`.`UserId` = `UserData`.`UserId` AND `Users`.`Username` = 'flipsIX'";
$selectQuery = mysql_query($queryString, $conDB);
return mysql_fetch_array($selectQuery);

 

I will still get the error.  I'm new to SQL and have only been working with it for a few days.  My php isn't great, but i'm not a complete idiot about it.  There's obviously something I'm not catching though.  Anyone have any ideas?

 

Btw, any of my other mysql_query function calls with a similar sort of $queryString works just fine.  This is the only one to work and the only one with a JOIN, but I coudln't possibly be the join could it? I don't understand how that would matter since mysql_query returns a resource identifier, but maybe there's soemthing about that I don't understand :/

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/177359-solved-mysql_fetch_array-problems/
Share on other sites

 

I see a return in there.  That means you're in a method or function.  And you are using $conDB.  Is this set outside of the function?  You do not need to assign mysql_connect to a variable.  But if you do, it is not automatically (super)global.  You can probably remove it from mysql_query in your function and php will try to use it automatically.  If that don't work, put

 

global $conDB;

 

inside your function.

Yeah, on the same page in fact.  This is my attempt at getting a users data from a seperate table after authenticating for login.  I'm able to compare the username and password just fine, then when it gets to that stuff, which isi n a seperate function, that won't work.  My actual code looks like this:

function getUserData($username) {
	$queryString = "SELECT `Noxxia9`.`UserData`.* FROM `Users` INNER JOIN `UserData` ON `Users`.`UserId` = `UserData`.`UserId` AND `Users`.`Username` = '$username'";
	//$queryString = "SELECT `Noxxia9`.`UserData`.* FROM `Users` INNER JOIN `UserData` ON `Users`.`UserId` = `UserData`.`UserId` AND `Users`.`Username` = 'flipsIX'";
	$selectQuery = mysql_query($queryString, $conDB);
	$result = mysql_fetch_array($selectQuery);
	return $result;
}

 

here's anotherone that works on the same page.

 

function pwCheck($username, $password, $conDB, $dbName, $tableName) {
	$queryString = "SELECT * FROM `$dbName`.`$tableName` WHERE `Username` = '$username' AND `Password` = '$password'";
	$selectQuery = mysql_query($queryString, $conDB);
	$result = mysql_fetch_array($selectQuery);
	if ($result == "") {
		return false;
	} else {
		return true;
	}
}

 

 

these used to be on the same page of generic functions i've made for myself in case I need them later, but I moved the first one listed (the one i'm having trouble with) to the same page as the login page thinking that maybe I messed up passing parameters.  I turned it from generic into very literal to help me narrow down the problem, and actually generated another, but this might help solve it. 

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource <dir stuff> on line 54

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource <dir stuff> on line 55

 

line 54 and line 55 are in getUserData().

 

the second function listed, works just fine and is only called 2 lines prior to the first function listed.

 

$password = encryptPW();
$validUser = pwCheck($_POST["username"], $password, $conNoxxia9, "Noxxia9", "Users");
if ($validUser) {
$userData = getUserData($_POST["username"]);

 

I see a return in there.  That means you're in a method or function.  And you are using $conDB.  Is this set outside of the function?  You do not need to assign mysql_connect to a variable.  But if you do, it is not automatically (super)global.  You can probably remove it from mysql_query in your function and php will try to use it automatically.  If that don't work, put

 

global $conDB;

 

inside your function.

 

ooops...you made me realize one mistake.  I forgot to do that after moving the function.

 

i still end up with my original error rather than the 2 errors now.  that was the reason I got two of them.

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.