Please Help- I think the problem is multiple queries on one page?

[php]<?php
session_start();
include_once ‘database.php’;
if(isset($_SESSION[‘uid’])) {
$query1 = “SELECT * FROM Users WHERE ID=” . $_SESSION[‘uid’];
$result1 = mysqli_query($con, $query1);
$id = mysqli_fetch_assoc($result1);
$query2 = “SELECT * FROM groups WHERE ID =” . $id;
$result2 = mysqli_query($con, $query2);
$name = mysqli_fetch_assoc($result2);
$page_title = "Group Jobs : " . $name[‘group_name’];
} else {echo(“HI!!!”);}
include_once ‘header.php’;
include_once ‘footer.php’;[/php]
the error: Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in /home/highvol3/public_html/groupjobs.php on line 10

I don’t think you’ll need this, but here’s a login: username John password doetheguy . Please help. I would greatly appreciate it.

  1. add error handling in case queries are failing.
  2. never add variables directly into queries, read up on binding parameters.

I guess your second query is failing because table groups does not exist (should be “Groups”), thus returning bool false. Note that this is just a wild guess based on the first query.

I’m so dumb! Line 8 should be [php]$query2 = “SELECT * FROM groups WHERE ID =” . $id[‘ID’];[/php]

I was following a tutorial when I made that table. My personal coding convention is firstSecond. his was like First_Second. Sometimes I use other conventions when I follow tutorials.

Sponsor our Newsletter | Privacy Policy | Terms of Service