iEntry 10th Anniversary Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > Putting it Together > Databases

Reply
 
LinkBack Thread Tools
Old January 31st, 2008, 02:17 PM   #1
New Member
 

Join Date: Mar 2007
Location: indiana
Age: 26
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 kidreapertronV is on a distinguished road
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

Code:
<?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

Code:
<?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:

Code:
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

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 UPDATE problem kidreapertronV PHP 2 January 31st, 2008 03:38 PM
First image problem and inline list problem konnor5092 HTML, XHTML and CSS 8 December 1st, 2007 06:08 AM
image problem SniperElite HTML, XHTML and CSS 31 August 28th, 2007 05:23 AM
Update Problem ringo26 HTML, XHTML and CSS 6 November 17th, 2006 03:07 AM
UPDATE information in access problem KingIsulgard Classic ASP 1 January 31st, 2006 10:09 AM


Search Engine Optimization by vBSEO 3.2.0 RC8