Jump to content

Uploading images and database script problem


benji87

Recommended Posts

Hi all im having trouble with a script ive created to upload a image to a web server and at the same time upload some data into a sql datbase including the url to the image thats been uploaded. This is basicly two seperate scripts merged into one so im not too sure if its the streamline way to do it. It doesnt seem to work though although i dont get any errors.

[code]<?
include 'db.php';

//GET VARIABLES

$title = $_POST['title'];
$message = $_POST['message'];
$publish = $_POST['publish'];

$title = stripslashes($title);
$message = stripslashes($message);

$date = date("j F");

//UPLOAD IMAGE

$imagename = basename($_POST['image_file']['name']);
//echo $imagename;

if(empty($imagename))
$error["imagename"] = "The name of the image was not found.";

if(empty($error))
{
$newimage = "../../images/newsimages/" . $imagename;
//echo $newimage;
$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
if(empty($result))
$error["result"] = "There was an error moving the uploaded file.";
}
//INSERT DATA INTO DATABASE

$sql = mysql_query("INSERT INTO ssrfc_news (title, message, publish, image, date)
VALUES('$title', '$message', '$publish', '$result', '$date')") or die (mysql_error());

if(!$sql){
echo 'There has been an error while trying to submit your post.';
} else {
$id = mysql_insert_id();
}
header("Location: ../news.php");
echo 'Your article has successfully been posted.';
?>[/code]

Any help would be great but im guessing that the problem lies around the $_post function.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.