Jump to content

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.

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.

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.