Click here to Skip to main content
14,241,538 members
Rate this:
Please Sign up or sign in to vote.
See more:
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 :

if(isset($_POST[submit])&& $_FILES['userfile']['size'] > 0)
{                  /*    So if it is set we�ll run for validation, */
$errors = array();

// Form Validation
$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));

// clean up data before putting in the database

 $information_id = mysql_prep($_GET['info']);
 $menu = trim(mysql_prep($_POST['menu']));  // cut out whitespace for menu

 $position = mysql_prep($_POST['position']);
 $visible = mysql_prep($_POST['visible']);
 $img_des = mysql_prep($_POST['img_des']);
 $content = mysql_prep($_POST['content']);

 $query = "INSERT INTO pages (
 menu, position, visible, img_des, image, content, information_id
 '{$menu}', {$position}, {$visible}, '{$img_des}', '{$image}', '{$content}',                                             {$information_id}

uploading code:

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);

    $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>";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100