i am new to php an developing cms for my project and am not able to insert a image or file in a database and my fields are id, information_id, menu, position, visible, img_des, image, content i just add a image to this now the problem is i dont know where to put the code and how to make alter
here my page creation :
MERGE THE CODE
if(isset($_POST[submit])&& $_FILES['userfile']['size'] > 0)
{
$errors = array();
$required_fields = array('menu', 'position', 'visible', 'img_des', 'content');
$errors = array_merge($errors, check_required_fields($required_fields, $_POST));
$fields_with_lengths = array('menu' => 30);
$errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST));
$information_id = mysql_prep($_GET['info']);
$menu = trim(mysql_prep($_POST['menu']));
$position = mysql_prep($_POST['position']);
$visible = mysql_prep($_POST['visible']);
$img_des = mysql_prep($_POST['img_des']);
$content = mysql_prep($_POST['content']);
if(empty($errors)){
$query = "INSERT INTO pages (
menu, position, visible, img_des, image, content, information_id
) VALUES (
'{$menu}', {$position}, {$visible}, '{$img_des}', '{$image}', '{$content}', {$information_id}
)";
uploading code:
<?php
require_once 'includes/session.php';
require_once 'includes/connect.php';
require_once 'includes/functions.php';
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
echo "<br>File $fileName uploaded<br>";
}
?>