如何在php中插入图像和日期

koaltpgm  于 2021-08-13  发布在  Java
关注(0)|答案(1)|浏览(450)
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\u admin\admin\postreate.php中的未定义索引:temp\u name
得到这个错误-但邮政正在得到完美的插入

ca1c2owp

ca1c2owp1#

您正在列位置使用function now()
例如,您应该编写列名 created_at 如果你想要当前的时间戳值 values 现在就写()

相关问题