dongxian6715 2017-12-05 13:33
浏览 30
已采纳

尝试使用php上传时出现Sql问题

I'm trying to upload a video to a folder which is working but, the relevant entry in the DB isn't occurring to match it. Really having trouble seeing what's wrong, as no errors are reported.

    session_start();
    require 'db.php';
    $name = $_FILES['video']['name'];
    $uploader = $_SESSION['first_name'].$_SESSION['last_name'];
    $newstring = $_SESSION['last_name'].'_'.$_SESSION['first_name'].'_'.date('ymdhms').".mp4";
    $extension = strtolower(substr($name, strpos($name, '.') + 1));
    $size = $_FILES['video']['size'];
    $max_size = '1073741824';
    $type = $_FILES['video']['type'];
    $id = $_SESSION['id'];
    $date = date('Y-m-D');
    $tmp_name = $_FILES['video']['tmp_name'];

    if(!empty($name)){
        $location = "uploads/";

    if($extension=='mp4'&&$type == 'video/mp4'){
        if($size <= $max_size){
            if(move_uploaded_file($tmp_name, $location.$newstring)){ 
                $sql = "INSERT INTO videos (file_name, upload_by, date) VALUES 
                   ('$newstring', '$id', '$date')";
                mysqli_query($mysqli, $sql);
                require('profile.php');
                $_SESSION['message'] = "Upload Successful!";
                header('Refresh:0; url=profile.php');
            }else{
                $_SESSION['message'] = "File failed to upload";
                header("location: error.php");
            }

I'm not getting a corresponding DB entry. Any help would be really appreciated.

  • 写回答

1条回答 默认 最新

  • douxiangbiao1899 2017-12-08 07:14
    关注

    Try this:

    $sql = "INSERT INTO videos (file_name, upload_by, date) VALUES 
                       ('".$newstring."', '".$id."', '".$date."')";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3