dongxiong2000 2013-07-31 19:59
浏览 75
已采纳

在SQL查询上获取错误,但正在使用正确的信息更新数据库

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");
}
  • 写回答

2条回答 默认 最新

  • dongqian7545 2013-07-31 20:04
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP