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();
}
}
?>