[SOLVED] Image UPDATE problem

This is a discussion on "[SOLVED] Image UPDATE problem" within the PHP Forum section. This forum, and the thread "[SOLVED] Image UPDATE problem are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jan 31st, 2008, 16:22
Junior Member
Join Date: Mar 2007
Location: indiana
Age: 25
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to kidreapertronV
[SOLVED] 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!
Reply With Quote

  #2 (permalink)  
Old Jan 31st, 2008, 17:11
Junior Member
Join Date: Mar 2007
Location: indiana
Age: 25
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to kidreapertronV
Re: Image UPDATE problem

Also, the page stops loading at the or die().... here.

PHP: Select all

<?php 
//Writes the photo to the server 
if (move_uploaded_file($_FILES['photo']['tmp_name'], $target) or die (mysql_error())) {
Reply With Quote
  #3 (permalink)  
Old Jan 31st, 2008, 18:38
Junior Member
Join Date: Mar 2007
Location: indiana
Age: 25
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to kidreapertronV
Re: [SOLVED] Image UPDATE problem

For the love of god... NEVER forget the darned

PHP: Select all

enctype="multipart/form-data" 

That's all it was. Thanks for looking!
Reply With Quote
Reply

Thread Tools

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 Upload Problem kidreapertronV PHP Forum 1 Jan 31st, 2008 18:38
Image UPDATE problem kidreapertronV Databases 0 Jan 31st, 2008 17:17
[SOLVED] div background image problem in ie Rincewind Web Page Design 7 Nov 30th, 2007 09:30
[SOLVED] Php/Mysql Image Problem longstand PHP Forum 6 Oct 17th, 2007 17:27
[SOLVED] Image script problem philsando JavaScript Forum 5 Oct 4th, 2007 13:58


All times are GMT. The time now is 05:54.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

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