dongzhun4898 2015-06-22 00:50
浏览 27
已采纳

数据库上传不起作用[关闭]

I am trying to upload the name of an image and the name of the user to a database already created and its not working. Everything in the code is working(putting the file in the file system etc) less putting the name of the file in the database. I've tried without the ,now() and everything and its still not working.

 <?php
include_once("php_includes/check_login_status.php");

if($_FILES['image']['name'])
{
    $fileName = $_FILES["image"]["name"];
    $kaboom = explode(".", $fileName);
    $fileExt = end($kaboom);
    $db_file_name = date("DMjGisY")."".rand(1000,9999).".".$fileExt;  
    $destination_path = getcwd()."/user/$log_username/$db_file_name";
    $target_path = $destination_path . basename( $_FILES["image"]["name"]);
    move_uploaded_file($_FILES['image']['tmp_name'], $target_path);
}

$sql="INSERT INTO photos(user,filename) VALUES('$log_username', '$db_file_name',now()))";

$query = mysqli_query($db_conx, $sql);

    if($query)
    echo "Image uploaded";
    else
    echo "ERROR";
    /*<script> location.replace('../user.php?u=<?php echo $log_username;?>'); </script> */
?>
  • 写回答

2条回答 默认 最新

  • douzhangkui2467 2015-06-22 01:01
    关注

    Problem is with your sql query. It has a binding error & an extra parenthesis.

    $sql="INSERT INTO photos(user,filename) VALUES('$log_username', '$db_file_name',now())";
    

    You are specifying two fields user,filename but passing three args '$log_username', '$db_file_name',now()

    Correct query would be (assuming you have an DEFAULT Time stamp column in the table, otherwise you have to specify the column name for that field as well),

     $sql="INSERT INTO photos(user,filename) VALUES('$log_username', '$db_file_name')";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备