I really need your help. I am trying to upload an image with php code. When I use different .php file with only upload code, it works, but when I try to add to my main code where I have this information which is posted into database.
I have this added and as I said it works with separate code only for upload.
form action="core/books-reg.php" method="POST" enctype="multipart/form-data"
This is my main .php code in where I want to make it work. Code starts after !empty(Description). The database takes the name and puts in mysql but there is no file in my folder. any help or other method would be really good.
<?php
session_start();
require("dbc.php");
$username = $_SESSION['username'];
$title = $_POST['title'];
$con = $_POST['con'];
$price = $_POST['price'];
$prodcode = $_POST['prodcode'];
$isbn = $_POST['isbn'];
$publisher = $_POST['publisher'];
$pages = $_POST['pages'];
$description = $_POST['description'];
$year = $_POST['year'];
$course = $_POST['course'];
$module = $_POST['module'];
if(!empty($title))
{
if(!empty($price))
{
if(!empty($prodcode))
{
if(!empty($isbn))
{
if(!empty($publisher))
{
if(!empty($pages))
{
if(!empty($description))
{
if (!isset($_FILES['image']['tmp_name'])) {
echo "";
}else{
$file=$_FILES['image']['tmp_name'];
$image= addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name= addslashes($_FILES['image']['name']);
move_uploaded_file($_FILES["image"]["tmp_name"],"upload/" . $_FILES["image"]["name"]);
$location="upload/" . $_FILES["image"]["name"];
}
mysql_query("INSERT INTO `books` (username,title,con,price,prodcode,isbn,publisher,pages,description,image,year,course,module) VALUES('$username','$title','$con','$price','$prodcode','$isbn','$publisher','$pages','$description','$image_name','$year','$course','$module')");
header("location: ../add_books.php?feedback=Your book has been put on the books page.");
}
else
{
header("location: ../add_books.php?feedback=Description field is empty");
}
}
else
{
header("location: ../add_books.php?feedback=Pages field is empty");
}
}
else
{
header("location: ../add_books.php?feedback=Publisher field is empty");
}
}
else
{
header("location: ../add_books.php?feedback=ISBN field is empty");
}
}
else
{
header("location: ../add_books.php?feedback=Product code field is empty");
}
}
else
{
header("location: ../add_books.php?feedback=Price field is empty");
}
}
else
{
header("location: ../add_books.php?feedback=Title field is empty");
}
?>