Solved

update query problem for image upload

Posted on 2011-03-08
6
399 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP AJAX Wordpress 9 21
Really simple no curl. Send a post 3 times 4 25
PHP Form Calculate Total Price 10 43
PHP Syntax Error 4 27
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

803 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