Jump to content

problem with mysqli query


kgo

Recommended Posts

Hi guys, having an issue with this query.

 

$userid = mysqli_query($link, "SELECT id FROM members WHERE username = '$username'");
if (!$userid)
	{
		$error = 'error error error';
		include 'error.php';
		exit();
	}
else
$result = mysqli_query($link, "SELECT game_name FROM usergames INNER JOIN games ON game_id = usergames.gameid WHERE usergames.userid = '$userid'");

 

etcetc...

 

getting this error: 'Catchable fatal error: Object of class mysqli_result could not be converted to string'

 

any ideas?

 

Link to comment
https://forums.phpfreaks.com/topic/195074-problem-with-mysqli-query/
Share on other sites

You are putting $userid, the result resource from the first query, into the second query statement.

 

You would need to fetch data from the result set of the first query before you could put an actual value into the second query.

 

oh of course, now I feel stupid heh.

 

I'm quite a newb, which function should I use if I'm retrieving a user id.. mysqli_fetch_something?

I changed it to this:

 

$userid = mysqli_query($link, "SELECT id FROM members WHERE username = '$username'");
$userid = mysqli_fetch_row($userid);
if (!$userid)
	{
		$error = 'I suck';
		include 'error.php';
		exit();
	}
else
$result = mysqli_query($link, "SELECT game_name FROM games INNER JOIN usergames ON game_id = usergames.gameid WHERE usergames.userid = '$userid'");
if (!$result)
	{
		$error = 'Error fetching info from database!';
		include 'error.php';
		exit();
	}
while ($row = mysqli_fetch_array($result))
	{
		$usergames[] = array('game_name' => $row['game_name']);
	}

 

but no data is displayed. however if I replace $userid (in the $result query) with an actuall user id, say '3' then the query works and my data is shown. at a loss.

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.