How to upload image to database and move into image folder this is my function for other rows:

<?php
function add_post($title, $contents, $category) {
    $title      = mysql_real_escape_string($title);
    $contents   = mysql_real_escape_string($contents);
    $category   = (int) $category;
    //var_dump($category);

    mysql_query("INSERT INTO `posts` SET

            `cat_id`        = '{$category}',
            `title`         = '{$title}',
            `image`         = '{$image}',
            `contents`      = '{$contents}',
            `date_posted`   = NOW()");
}

und this is post page:

<?php 
    include_once('../resources/init.php'); 


    if ( isset($_POST['title'], $_POST['contents'], $_POST['category']) ) {
            //var_dump($_POST);
        $errors = array();

        $title      = trim($_POST['title']);
        $contents   = trim($_POST['contents']);

        if ( empty($title)) {
            $errors[] = 'You need to supply a title';
        } else if ( strlen($title) > 255 ){
            $errors[] = 'The title can not be longer than 255  characters'; 
        }
        if ( empty($contents) ) {
            $errors[] = 'You need to supply some text';
        }
        if ( ! category_exists('id', $_POST['category']) ){
            $errors[] = 'That category does not exist'; 
        }

        if ( empty($errors) ) {
            add_post($title, $contents, $_POST['category']);

            $id = mysql_insert_id();

            header('location: add_post.php?id=' . $id);
            die();
        }
    }
?>

$uploadDir = 'backend/'; //path for where u have to upload
$filename = $_FILES['photo']['name'];
$tmpname = $_FILES['photo']['tmp_name'];

$filePath = $uploadDir . $filename;
$result1 = move_uploaded_file($tmpname, $filePath);

insert into review (id,filename, filepath) values('','$filename','$filePath')");

<input type="file" name="photo">

Thanks!

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.