0

I'm getting the error: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in /home/content/57/8912457/html/brick-academy/add_file.php on line 34.

I can't figure out why it's giving that error, considering the code looks fine and it is inputing the correct data into the correct fields in the database.

The error is stopping the rest of my script from running.

Any help would be appreciated.


Code:

include_once('resources/init.php');
include_once('user_check.php');

$name = $_POST['name'];
$teacher = $_POST['teacher'];

$query = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT name_first, name_last FROM teachers WHERE teacher_id='$teacher'");
$row = mysqli_fetch_assoc($query);
$name_first = $row['name_first'];
$name_last = $row['name_last'];
$folder_name = $name_last . "-" . $name_first . "-ID-" . $teacher . "/";


$dirname = "files/" . $folder_name;
if(!is_dir($dirname)){
    mkdir($dirname);
}

$dirname = $dirname .  $_FILES['file']['name'];


if(move_uploaded_file($_FILES['file']['tmp_name'], $dirname)){

    $query = mysqli_query($GLOBALS["___mysqli_ston"], "INSERT INTO documents SET id_teacher = '$teacher', name = '$name', document =  '$dirname'");
    $row = mysqli_fetch_assoc($query);

    header("location:file_manager.php");
}
Jacques ジャック
  • 3,682
  • 2
  • 20
  • 43
  • $GLOBALS["___mysqli_ston"] doesn't appear to be an initialized mysqli link – Moylin Jul 31 '13 at 20:03
  • Added the rest of the code for your benefit. It's in one of the includes. – Jacques ジャック Jul 31 '13 at 20:05
  • possible duplicate of [mysql\_fetch\_array() expects parameter 1 to be resource, boolean given in select](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in-select) – John Conde Aug 01 '13 at 00:18

2 Answers2

1

Remove $row = mysqli_fetch_assoc($query);

If you look at the documentation for mysqli_query, it shows that it will return a boolean value for any insert queries instead of a mysql resource.
Since you're not even attempting to use $row in any place, you can get rid of the line.

Trenton Trama
  • 4,890
  • 1
  • 22
  • 27
0

change this:

$row = mysqli_fetch_assoc($query);

to this:

$row = mysqli_fetch_row($query);
Maximus2012
  • 1,799
  • 2
  • 12
  • 15