Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

update query problem for image upload

Posted on 2011-03-08
6
Medium Priority
?
406 Views
Last Modified: 2012-05-11
hey all. i found this image upload resizing script and am trying to add a bit to it to save the url to my images table in my db.

but its not updating the row in the table not sure why can u help please:


CREATE TABLE IF NOT EXISTS `images` (
  `PictureID` int(4) NOT NULL auto_increment,
  `MemberID` int(11) default NULL,
  `imgLarge` varchar(255) default NULL,
  `imgSmall` varchar(255) default NULL,
  PRIMARY KEY  (`PictureID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `images`
--

INSERT INTO `images` (`PictureID`, `MemberID`, `imgLarge`, `imgSmall`) VALUES
(3, 52, 'images/sml_71745-1920x1080-RED-SKULL.jpg', 'images/71745-1920x1080-RED-SKULL.jpg');


 

<form action="<?php echo $_server['php-self'];  ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
        <p>Change Profile picture:</p>
        <p>Picture must be a JPEG</p>
        <p>
          <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
      </p>
        <button name="submit" type="submit" class="submitButton">Upload/Resize Image</button>
</form>
<?php
        if(isset($_POST['submit'])){
          if (isset ($_FILES['new_image'])){
                     global $message;
              $imagename = $_FILES['new_image']['name'];
              $source = $_FILES['new_image']['tmp_name'];
              $target = "images/".$imagename;
              move_uploaded_file($source, $target);
 
              $imagepath = $imagename;
              $save = "images/" . $imagepath; //This is the new file you saving
              $file = "images/" . $imagepath; //This is the original file
 
              list($width, $height) = getimagesize($file) ;
 
              $modwidth = 286;
              $modheight = 269;
              $tn = imagecreatetruecolor($modwidth, $modheight) ;
              $image = imagecreatefromjpeg($file) ;
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
 
              imagejpeg($tn, $save, 100) ;
 
              $save = "images/sml_" . $imagepath; //This is the new file you saving
              $file = "images/" . $imagepath; //This is the original file
 
              list($width, $height) = getimagesize($file) ;
 
              $modwidth = 80;
 
              $diff = $width / $modwidth;
 
              $modheight = $height / $diff;
              $tn = imagecreatetruecolor($modwidth, $modheight) ;
              $image = imagecreatefromjpeg($file) ;
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
 
              imagejpeg($tn, $save, 100) ;
            echo "Large image: <img src='images/".$imagepath."'><br>";
            echo "Thumbnail: <img src='images/sml_".$imagepath."'>";
                  
                   include("conf.php");
    $connection = mysql_connect($databaseURL,$databaseUName,$databasePWord);
        // or die ("Error while connecting to localhost");
    $db = mysql_select_db($databaseName,$connection);
        //or die ("Error while connecting to database");
            
                  

            $query = "UPDATE `images` SET `imgLarge` = '".$file."', `imgSmall` = '".$save."' WHERE memberID = '".$MemberID."'";
            //$insert = mysql_query("INSERT INTO images (MemberID, imgLarge, imgSmall) VALUES ('$MemberID','$save', '$file')");
 mysql_close($connection);
          }
        }
?>
0
Comment
Question by:helpchrisplz
  • 5
6 Comments
 
LVL 1

Author Comment

by:helpchrisplz
ID: 35073572
i only want one user to have one profile picture at one time. please note the last query is commented out
0
 
LVL 1

Author Comment

by:helpchrisplz
ID: 35073620
and i haven't shown a query for how i populate $MemberID but its from another bit of code above
0
 
LVL 13

Expert Comment

by:dsmile
ID: 35079594
If you're running on a *nix OS, then case sensitive may be the problem

Try change this

$query = "UPDATE `images` SET `imgLarge` = '".$file."', `imgSmall` = '".$save."' WHERE memberID = '".$MemberID."'";

to this

$query = "UPDATE `images` SET `imgLarge` = '".$file."', `imgSmall` = '".$save."' WHERE MemberID = '".$MemberID."'";

or

$query = "UPDATE `images` SET `imgLarge` = '".$file."', `imgSmall` = '".$save."' WHERE `MemberID` = '".$MemberID."'";
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:helpchrisplz
ID: 35083367
i have got this far please help:

i have changed the names in my table to lower case but still have a capital if there is a second word.

CREATE TABLE IF NOT EXISTS `images` (
  `pictureId` int(4) NOT NULL auto_increment,
  `memberId` int(11) default NULL,
  `imgLarge` varchar(255) default NULL,
  `imgSmall` varchar(255) default NULL,
  PRIMARY KEY  (`pictureId`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `images`
--

INSERT INTO `images` (`pictureId`, `memberId`, `imgLarge`, `imgSmall`) VALUES
(3, 52, 'images/sml_71745-1920x1080-RED-SKUL.jpg', 'images/71745-1920x1080-RED-SKULL.jpg');



and this is my code as i have it now.
 i have echoed out all the variables used in the update query to check they are actually populated and they all are containing what they should be so am just unsure why this update is not actually updating:

$queryOne = mysql_query ("SELECT pictureId FROM images WHERE memberId = $MemberID");
            

$row = mysql_fetch_array($queryOne);

$pictureId = $row['pictureId'];
echo $pictureId;
            

$UPDATE = "UPDATE `images` SET `imgLarge` = '".$file."', `imgSmall` = '".$save."', `memberId` = '".$MemberID."' WHERE `images`.`pictureId` = '".$pictureId."'";

            
 echo $file; // this does echo the url for the large file but update query does not save it to db
 echo $save; // this does echo the url for the small file but update query does not save it to db
0
 
LVL 1

Accepted Solution

by:
helpchrisplz earned 0 total points
ID: 35088427
fixed: i was silly and forgot the mysql_connect *bangs head*
0
 
LVL 1

Author Closing Comment

by:helpchrisplz
ID: 35126411
mysql_connect was missing
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question