View Single Post
  #1 (permalink)  
Old 07-01-09, 08:46 PM
SniperTowers SniperTowers is offline
Wannabe Coder
 
Join Date: Dec 2008
Posts: 143
Thanks: 5
Thanked 0 Times in 0 Posts
PHP Thumnail Adding

PHP Code:

<?php

session_start
();
// Admin Section
require ("connect.php");
require(
"functions.php"); 
include(
"template/header.php");
if(
$_SESSION['status'] != 2){
    die(
'You must be an administrator to access this section; please <a href="login.php">login</a>');
}
echo 
"<a href=\"admin.php\">Return to admin section!</a></br><br/><br/>";

echo 
"Here you can add a thumbnail to a layout.<br/><br/>";


echo 
"Add a thumbnail<br/><br/>";
if(!isset(
$_POST['submit'])){
        echo 
"<form action=\"\" method=\"post\" enctype=\"multipart/form-data\">";
    echo 
"<select name=\"title\">";
    
$result mysql_query("SELECT * from layouts WHERE id ORDER BY `title` ASC");
    while(
$list mysql_fetch_array$result )){
    
$title $list['title'];  
    
$cid $list['id'];
    echo 
"<option value=\"$cid\">$title</option>";
    }
    echo 
"</select>";
echo 
"<br/>Display image (100px x 100px): <input id=\"file\" type=\"file\" name=\"file\"/><br />";
        echo 
"<br/><input type=\"submit\" name=\"submit\" value=\"Create layout!\">
        </form>"
;
        }else{
      
$rand rand(0,999999);
      
move_uploaded_file($_FILES["file"]["tmp_name"], "images/" "$rand$_FILES["file"]["name"]);
      
$image "$rand$_FILES["file"]["name"];
      if(empty(
$_FILES["file"]["name"])){
          
$image "none.jpeg";
}
 
        
mysql_query("UPDATE layouts SET thumbnail = '$image' WHERE title='$title'" or die(mysql_error()));
        echo 
"The layout has been created!";
        echo 
"$title";
        }
        include(
"template/footer.php");
?>
Here I'm trying to upload a thumnail image to the database, the image uploads into the folder but I can't get it to update the database. When the layout is added it updates the thumbnail field as '0' but I'm trying to replace it with the filename. What am I doing wrong?

Thanks
Reply With Quote