Web Design and Development Forums

Image UPDATE problem

This is a discussion on "Image UPDATE problem" within the MySQL section. This forum, and the thread "Image UPDATE problem are both part of the Databases category.


Go Back   Webforumz.com > Databases > MySQL

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Jan 31st, 2008, 17:17   #1 (permalink)
Junior Member
 
Join Date: Mar 2007
Location: indiana
Age: 25
Posts: 38
Send a message via AIM to kidreapertronV
Image UPDATE problem

Hello all,

I've created an image upload form that has been working successfully when I try to add a listing with an image or delete image information from the database (I am not storing the image in the database, I move the file to an images folder the server). I'm running into problems when I try to update an already existing listing.

When I was error catching, MySQL echoed an error that showed me that '$photo' was blank on the editsave.php page (the page where the actual MySQL UPDATE command takes place). I'm not sure why it is not carrying to this page. Any help would be lovely!

Here's the code.

edit.php

PHP: Select all

<?php
    
if (isset($_POST['submit'])) {

            include(
"../connect.php");    
                
            
$query "SELECT * FROM sponsors WHERE sponsor_id={$_POST['sponsor_id']}";
             
$results mysql_query($query);
                
            
$row mysql_fetch_array($results) or die(mysql_error()); 
                    
            
$sponsor_id $row['sponsor_id'];
            
$name htmlentities($row['name']);
            
$website htmlentities($row['website']);
            
$element htmlentities($row['element']);
            
$since $row['since'];
                
            
trim($level);
            
addslashes($name);
            
addslashes($element);
?>
                <form action="sponsor_editsave.php" method="POST">
                    <p>Sponsor/Company Name: <input type="text" name="name" size="30" maxsize="100" value="<?php echo $name?>" /></p>
                    <p>Website: <input type="text" name="website" size="30" maxsize="40" value="<?php echo $website?>" /></p>
                    <p>Element: <input type="text" name="element" size="20" maxsize="30" value="<?php echo $element?>" /></p>
                    <p>Sponsor since: <input type="text" name="since" size="4" maxsize="4" value="<?php echo $since?>" /></p>
            <?php
                   
if ($photo != NULL){
                    echo 
"<img src=\"http://www.campyale.com/sponsors/images/".$row['photo'] ."\" />";
            
?> 
                </form>   
                    <form action="sponsor_delete_logo.php" method="post">
                        <input type="hidden" name="sponsor_id" value="<?php echo $sponsor_id?>">
                        <p><input type="submit" name="logo_delete" value="Delete Logo" /></p>
                    </form>
                <form action="sponsor_editsave.php" method="POST">
            <?php
                
} else {
            
?>   
                     <p>Sponsor Logo: <input type="file" name="photo" /></p>       
            <?php
                
}
            
?>                   
                    <form action="sponsor_editsave.php" method="post">
                        <input type="hidden" name="sponsor_id" value="<?php echo $sponsor_id?>">
                        <p><input type="submit" name="submit" value="Save Changes" /></p>
                    </form>
                    <form action="index.php" method="post">
                        <p><input type="submit" name="submit" value="Cancel" /></p>
                    </form>
                </form>
            <?php
            
} else {
                echo 
"<p>Info not properly submitted. </p>";
                
mysql_close(); //Closes our SQL session
            
}
            
?>
editsave.php

PHP: Select all

<?php
            
//This is the directory where images will be saved 
            
$target "../images/"
            
$target $target basename$_FILES['photo']['name']); 

            if (isset(
$_POST['submit'])) {
                
// connect to database
                
include("../connect.php");    
                
                
$sponsor_id $_POST['sponsor_id'];
                
$name $_POST['name'];
                
$website $_POST['website'];
                
$element $_POST['element'];
                
$since $_POST['since'];
                
$photo = ($_FILES['photo']['name']); 
                
                
$website htmlentities($website);
                
                
$name trim($name);
                
$element trim($element);
                
                
$name addslashes($name);
                
$element addslashes($element);

                
//Define the query
                
$query "UPDATE sponsors SET name='$name', website='$website', element='$element', since='$since', photo='$photo' WHERE sponsor_id={$sponsor_id}";
                
//run the query
               
if (@mysql_query ($query)) { 
            
?>
                 <p>The sponsor was successfully updated.</p>
            <?php 
                    
//Writes the photo to the server 
                    
if (move_uploaded_file($_FILES['photo']['tmp_name'], $target) or die (mysql_error())) { 
                    
                    
//Tells you if its all ok 
                        
echo "<p>The file "basename$_FILES['uploadedfile']['name']). " has been uploaded, and the information has been updated in the directory</p>"
                    } else { 
                        
//Gives an error if its not 
                        
echo "<p>Sorry, there was a problem uploading your file.</p>"
                    }
                } else { 
            
?>
                 <p>The sponsor could not be saved.</p>
            <?php 
                mysql_close
(); //Closes our SQL session
                
}
            } else {
            
?>
                 <p>There is no data to process.</p>
            <?php
            
}
            
?>
Thanks for any help!

Also, the page stops loading right at the:

PHP: Select all

if (move_uploaded_file($_FILES['photo']['tmp_name'], $target) or die (mysql_error())) { 

If that offers any clues...

Thanks again!
kidreapertronV is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Image UPDATE problem kidreapertronV PHP Forum 2 Jan 31st, 2008 18:38
First image problem and inline list problem konnor5092 CSS Forum 8 Dec 1st, 2007 09:08
image problem SniperElite HTML Forum 31 Aug 28th, 2007 08:23
Update Problem ringo26 HTML Forum 6 Nov 17th, 2006 06:07
UPDATE information in access problem KingIsulgard ASP Forum 1 Jan 31st, 2006 13:09



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 05:32.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59