【问题标题】:How to insert image and date in php如何在php中插入图像和日期
【发布时间】:2020-09-18 17:11:22
【问题描述】:
if(isset($_POST['post-submit'])){

    $post_category_id = $_POST['post_category_id'];
    $post_title = $_POST['post_title'];
    $post_author = $_POST['post_author']; 
    $post_tags = $_POST['post_tags'];
    $post_status = $_POST['post_status'];

    $post_content = $_POST['post_content'];
    // SQL Injection
    $post_content = mysqli_real_escape_string($connection, $post_content );

    $post_date = date('d-m-y');
    $post_comment_count = 4;

    $post_image = $_FILES['image']['name'];
    $post_image_temp = $_FILES['image']['temp_name'];
    move_uploaded_file($post_image_temp, "../img/blog/$post_image" );

    $query  = "INSERT INTO posts(post_image,post_date,post_comment_count, post_category_id, post_title, post_author, post_tags, post_status, post_content) " ;
    $query .= "VALUES('$post_image', now(), '$post_comment_count' ,'$post_category_id','$post_title','$post_author','$post_tags','$post_status','$post_content')";

    $insert_all_post_query = mysqli_query($connection, $query);

    if(!$insert_all_post_query) {
      die("QUERY FAILED" . mysqli_error($connection));   
    } else {
      echo "<h2>Data Sucessfully Updated</h2>";
    }
}

注意:未定义索引:第 35 行 C:\xampp\htdocs\cms_admin\admin\postCreate.php 中的 temp_name

收到此错误 - 但帖子已完美插入

【问题讨论】:

  • edit您的问题向我们展示您的错误发生的代码。

标签: php mysql sql post insert


【解决方案1】:

您正在列位置使用函数 now()

你应该写列名,例如created_at 如果你想要values 中的当前时间戳值,现在写在那里()

【讨论】:

  • 嗨哥们,我已经更新了代码并得到了这个错误,请帮助我
  • 你真是个了不起的人。它有效,但问题是图像没有上传到目录中,只有值存储在数据库中
  • 用它代替你的代码 move_uploaded_file($post_image_temp, "../img/blog/" .basename($post_image) );
  • John Deo 是正确的,你应该使用 tmp_name 而不是 temp_name
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-15
  • 1970-01-01
  • 2021-07-27
  • 1970-01-01
  • 2015-02-20
  • 2013-10-17
  • 2013-06-18
相关资源
最近更新 更多