Solved

update query problem for image upload

Posted on 2011-03-08
6
400 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 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