Solved

PHP and MySQL Upload Image to DB and show image on main page

Posted on 2007-11-17
51
415 Views
Last Modified: 2013-12-13
Hello.  I think I got this script mostly down I copied it from a previous post; however I'm getting a line on error 57

Warning: mysql_query() [function.mysql-query]: Access denied for user 'heart2'@'localhost' (using password: NO) in /home2/heart2/public_html/chris/upload5.php on line 57

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home2/heart2/public_html/chris/upload5.php on line 57

my link is at:
http://www.jocosingles.com/chris/upload1.php?ind_id=3

I'm passing the param ind_id=3 from a Member Table as a URL parameter on the form to idenfity that record.  Is the script on line 57 saying that the DB link goes into a table called "Individual" and a field name named "pic1"?  I'm trying to upload the file to the server and link to it on the webpage.

Also, how do you link to the photo once the link is in the db?  I'm trying to get it to show up on a main menu sort of page.  I'm a beginner with PHP pretty much and I just would like to copy/paste code.  I'm trying to get the picture to post on the main menu page once it's uploaded and linked.  Thanks for any help!
0
Comment
Question by:chrisdavis5
  • 29
  • 22
51 Comments
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306669
First of all you need to connect to the database properly, apparently you are using the wrong username, is your usrename heart2? by default the username is 'root' with no password.
Have you tried that combination?
0
 

Author Comment

by:chrisdavis5
ID: 20306695
oh no, in my "connect1.inc" file everything seems to be in order..I checked the db user name and pass to make sure..
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306701
hmmm yes but this:
Warning: mysql_query() [function.mysql-query]: Access denied for user 'heart2'@'localhost' (using password: NO) in /home2/heart2/public_html/chris/upload5.php on line 57

suggests otherwise. it is saying that you are connecting using the username heart2 to the mysql server localhost without using a password and getting an access denied, thus subsequently your mysql_query() function doesn't work either because you are not connected to the database.

Have you connected to the database successfully before?
0
 

Author Comment

by:chrisdavis5
ID: 20306724
If I change the "connect1.php" include to "connect.php" (where there is none), it gives me this:

Warning: main(connect.inc) [function.main]: failed to open stream: No such file or directory in /home2/heart2/public_html/chris/upload5.php on line 2

Warning: main(connect.inc) [function.main]: failed to open stream: No such file or directory in /home2/heart2/public_html/chris/upload5.php on line 2

Warning: main() [function.include]: Failed opening 'connect.inc' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home2/heart2/public_html/chris/upload5.php on line 2

Warning: mysql_query() [function.mysql-query]: Access denied for user 'heart2'@'localhost' (using password: NO) in /home2/heart2/public_html/chris/upload5.php on line 57

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home2/heart2/public_html/chris/upload5.php on line 57

I am pretty sure my connections are correct in my "connect1.php" file..
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306730
maybe you ought to try a manual connection:

try:

$conn = mysql_connect('your_server','username','password');
if(!$conn)
   die("Cannot connect!");
0
 

Author Comment

by:chrisdavis5
ID: 20306737
Good thinking but that didn't work either..I am using SQLYOG to connect to the server with the same params that are in my connect1.inc file and I connect okay..is there something in the code?

Also, I'm assuming I have a table called "Individual" and a field name named "pic1" for that SQL SET to work??

0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306742
so hang on, just to confirm my above code outputted Cannto Connect?
0
 

Author Comment

by:chrisdavis5
ID: 20306748
No the page was blank when I uncommented the original "connect1.inc" line and put yours in there..then the code below it.  The page didn't say anything on there...

P.S. I don't mind if you use my username/password/db, it's just a testing server...I didn't see a space to put the DB name..below the connection code is part of the rest of the document but you get the point..

<?php
//include 'common.inc'; // file to connect to the db
$conn = mysql_connect('localhost','heart2_upload','test1');
if(!$conn)
   die("Cannot connect!");

$ind_id = $_POST['ind_id'];
$idir = "images/";   // Path To Images Directory
$tdir = "images/thumbs/";   // Path To Thumbnails Directory
$twidth = "300";   // Maximum Width For Thumbnail Images
$theight = "300";   // Maximum Height For Thumbnail Images

0
 

Author Comment

by:chrisdavis5
ID: 20306752
P.S I changed "connect1.inc" to "common.inc" and that didn't do anything either..just another reference to it I guess.
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306754
ahh if it didn't output "Cannot Connect!" then you have connected to the database properly! Where is your code for mysql_query() functioN?
0
 

Author Comment

by:chrisdavis5
ID: 20306775
<?php
//include 'connect1.inc'; // file to connect to the db
$conn = mysql_connect('localhost','heart2_upload','test1');
if(!$conn)
   die("Cannot connect!");

$ind_id = $_POST['ind_id'];
$idir = "images/";   // Path To Images Directory
$tdir = "images/thumbs/";   // Path To Thumbnails Directory
$twidth = "300";   // Maximum Width For Thumbnail Images
$theight = "300";   // Maximum Height For Thumbnail Images


//if (!isset($_GET['subpage'])) {   // Image Upload Form Below

  if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') {   // Uploading/Resizing Script
  $url = $_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use
  if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") {
    $file_ext = strrchr($_FILES['imagefile']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php
    $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']);   // Move Image From Temporary Location To Permanent Location
    if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location
      //print 'Image uploaded successfully.<br />';   // Was Able To Successfully Upload Image
      $simg = imagecreatefromjpeg("$idir" . $url);   // Make A New Temporary Image To Create The Thumbanil From
      $currwidth = imagesx($simg);   // Current Image Width
      $currheight = imagesy($simg);   // Current Image Height
      if ($currheight > $currwidth) {   // If Height Is Greater Than Width
         $zoom = $twidth / $currheight;   // Length Ratio For Width
         $newheight = $theight;   // Height Is Equal To Max Height
         $newwidth = $currwidth * $zoom;   // Creates The New Width
      } else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)
        $zoom = $twidth / $currwidth;   // Length Ratio For Height
        $newwidth = $twidth;   // Width Is Equal To Max Width
        $newheight = $currheight * $zoom;   // Creates The New Height
      }
      $dimg = imagecreate($newwidth, $newheight);   // Make New Image For Thumbnail
      imagetruecolortopalette($simg, false, 256);   // Create New Color Pallete
      $palsize = ImageColorsTotal($simg);
      for ($i = 0; $i < $palsize; $i++) {   // Counting Colors In The Image
       $colors = ImageColorsForIndex($simg, $i);   // Number Of Colors Used
       ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use
      }
      imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);   // Copy Resized Image To The New Image (So We Can Save It)
      imagejpeg($dimg, "$tdir" . $url);   // Saving The Image
      imagedestroy($simg);   // Destroying The Temporary Image
      imagedestroy($dimg);   // Destroying The Other Temporary Image
     // print 'Image thumbnail created successfully.';   // Resize successful
     print "Image uploaded/changed";
    } else {
      print '<font color="#FF0000">ERROR: Unable to upload image.</font>';   // Error Message If Upload Failed
    }
  } else {
    print '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is ';   // Error Message If Filetype Is Wrong
    print $file_ext;   // Show The Invalid File's Extention
    print '.</font>';
  }
}

$result = mysql_query("UPDATE `Individual`
                        SET `pic1` = '<a href=\"http://www.jocosingles/chris/$idir$url\" target=\"top\"><img src=\"http://www.jocosingles/chris/$tdir$url\" border=\"0\"></a>'
                                    WHERE ind_id = '$ind_id'");
                                    
?>


IT IS complaining about the WHERE ind_id = $ind_id line I believe..I have a table called "Individual" and a field name named "pic1"..no go so far..LOL
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306785
Try this see if there's any change.
<?php

//include 'connect1.inc'; // file to connect to the db

$conn = mysql_connect('localhost','heart2_upload','test1');

if(!$conn)

   die("Cannot connect!");
 

$ind_id = $_POST['ind_id'];

$idir = "images/";   // Path To Images Directory

$tdir = "images/thumbs/";   // Path To Thumbnails Directory

$twidth = "300";   // Maximum Width For Thumbnail Images

$theight = "300";   // Maximum Height For Thumbnail Images
 
 

//if (!isset($_GET['subpage'])) {   // Image Upload Form Below
 

  if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') {   // Uploading/Resizing Script

  $url = $_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use

  if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") {

    $file_ext = strrchr($_FILES['imagefile']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php

    $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']);   // Move Image From Temporary Location To Permanent Location

    if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location

      //print 'Image uploaded successfully.<br />';   // Was Able To Successfully Upload Image

      $simg = imagecreatefromjpeg("$idir" . $url);   // Make A New Temporary Image To Create The Thumbanil From

      $currwidth = imagesx($simg);   // Current Image Width

      $currheight = imagesy($simg);   // Current Image Height

      if ($currheight > $currwidth) {   // If Height Is Greater Than Width

         $zoom = $twidth / $currheight;   // Length Ratio For Width

         $newheight = $theight;   // Height Is Equal To Max Height

         $newwidth = $currwidth * $zoom;   // Creates The New Width

      } else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)

        $zoom = $twidth / $currwidth;   // Length Ratio For Height

        $newwidth = $twidth;   // Width Is Equal To Max Width

        $newheight = $currheight * $zoom;   // Creates The New Height

      }

      $dimg = imagecreate($newwidth, $newheight);   // Make New Image For Thumbnail

      imagetruecolortopalette($simg, false, 256);   // Create New Color Pallete

      $palsize = ImageColorsTotal($simg);

      for ($i = 0; $i < $palsize; $i++) {   // Counting Colors In The Image

       $colors = ImageColorsForIndex($simg, $i);   // Number Of Colors Used

       ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use

      }

      imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);   // Copy Resized Image To The New Image (So We Can Save It)

      imagejpeg($dimg, "$tdir" . $url);   // Saving The Image

      imagedestroy($simg);   // Destroying The Temporary Image

      imagedestroy($dimg);   // Destroying The Other Temporary Image

     // print 'Image thumbnail created successfully.';   // Resize successful

     print "Image uploaded/changed";

    } else {

      print '<font color="#FF0000">ERROR: Unable to upload image.</font>';   // Error Message If Upload Failed

    }

  } else {

    print '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is ';   // Error Message If Filetype Is Wrong

    print $file_ext;   // Show The Invalid File's Extention

    print '.</font>';

  }

}
 

$result = mysql_query("UPDATE `Individual`

                        SET `pic1` = '<a href=\"http://www.jocosingles/chris/$idir$url\" target=\"top\"><img src=\"http://www.jocosingles/chris/$tdir$url\" border=\"0\"></a>'

                                    WHERE ind_id = $ind_id",$conn);

                                    

?>

Open in new window

0
 

Author Comment

by:chrisdavis5
ID: 20306790
hmm..no change, still a blank page..I'm upping the points LOL
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306797
so no error? just blank?

Bearing in mind that you have to supply an argument for your script as it is checking for the $_GET["subpage].

Try this and see what it prints out?
<?php

//include 'connect1.inc'; // file to connect to the db

$conn = mysql_connect('localhost','heart2_upload','test1');

if(!$conn)

   die("Cannot connect!");

 

$ind_id = $_POST['ind_id'];

$idir = "images/";   // Path To Images Directory

$tdir = "images/thumbs/";   // Path To Thumbnails Directory

$twidth = "300";   // Maximum Width For Thumbnail Images

$theight = "300";   // Maximum Height For Thumbnail Images

 

 

//if (!isset($_GET['subpage'])) {   // Image Upload Form Below

 

  if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') {   // Uploading/Resizing Script

  $url = $_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use

  if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") {

    $file_ext = strrchr($_FILES['imagefile']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php

    $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']);   // Move Image From Temporary Location To Permanent Location

    if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location

      //print 'Image uploaded successfully.<br />';   // Was Able To Successfully Upload Image

      $simg = imagecreatefromjpeg("$idir" . $url);   // Make A New Temporary Image To Create The Thumbanil From

      $currwidth = imagesx($simg);   // Current Image Width

      $currheight = imagesy($simg);   // Current Image Height

      if ($currheight > $currwidth) {   // If Height Is Greater Than Width

         $zoom = $twidth / $currheight;   // Length Ratio For Width

         $newheight = $theight;   // Height Is Equal To Max Height

         $newwidth = $currwidth * $zoom;   // Creates The New Width

      } else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)

        $zoom = $twidth / $currwidth;   // Length Ratio For Height

        $newwidth = $twidth;   // Width Is Equal To Max Width

        $newheight = $currheight * $zoom;   // Creates The New Height

      }

      $dimg = imagecreate($newwidth, $newheight);   // Make New Image For Thumbnail

      imagetruecolortopalette($simg, false, 256);   // Create New Color Pallete

      $palsize = ImageColorsTotal($simg);

      for ($i = 0; $i < $palsize; $i++) {   // Counting Colors In The Image

       $colors = ImageColorsForIndex($simg, $i);   // Number Of Colors Used

       ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use

      }

      imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);   // Copy Resized Image To The New Image (So We Can Save It)

      imagejpeg($dimg, "$tdir" . $url);   // Saving The Image

      imagedestroy($simg);   // Destroying The Temporary Image

      imagedestroy($dimg);   // Destroying The Other Temporary Image

     // print 'Image thumbnail created successfully.';   // Resize successful

     print "Image uploaded/changed";

    } else {

      print '<font color="#FF0000">ERROR: Unable to upload image.</font>';   // Error Message If Upload Failed

    }

  } else {

    print '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is ';   // Error Message If Filetype Is Wrong

    print $file_ext;   // Show The Invalid File's Extention

    print '.</font>';

  }

}

 

$result = mysql_query("UPDATE `Individual`

                        SET `pic1` = '<a href=\"http://www.jocosingles/chris/$idir$url\" target=\"top\"><img src=\"http://www.jocosingles/chris/$tdir$url\" border=\"0\"></a>'

                                    WHERE ind_id = $ind_id",$conn);
 

if($result)

	echo "the query has been successfully executed and database updated";

else 

	echo "error in your sql statement!";

                                    

?>

Open in new window

0
 

Author Comment

by:chrisdavis5
ID: 20306809
ahh it says error in SQL statement..but is it talking about the statement on the WHERE I'm assuming??
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306818
Try echoing out your query statement, it is probably not what you are expecting hence the error. copy and paste my code below..
<?php

//include 'connect1.inc'; // file to connect to the db

$conn = mysql_connect('localhost','heart2_upload','test1');

if(!$conn)

   die("Cannot connect!");

 

$ind_id = $_POST['ind_id'];

$idir = "images/";   // Path To Images Directory

$tdir = "images/thumbs/";   // Path To Thumbnails Directory

$twidth = "300";   // Maximum Width For Thumbnail Images

$theight = "300";   // Maximum Height For Thumbnail Images

 

 

//if (!isset($_GET['subpage'])) {   // Image Upload Form Below

 

  if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') {   // Uploading/Resizing Script

  $url = $_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use

  if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") {

    $file_ext = strrchr($_FILES['imagefile']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php

    $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']);   // Move Image From Temporary Location To Permanent Location

    if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location

      //print 'Image uploaded successfully.<br />';   // Was Able To Successfully Upload Image

      $simg = imagecreatefromjpeg("$idir" . $url);   // Make A New Temporary Image To Create The Thumbanil From

      $currwidth = imagesx($simg);   // Current Image Width

      $currheight = imagesy($simg);   // Current Image Height

      if ($currheight > $currwidth) {   // If Height Is Greater Than Width

         $zoom = $twidth / $currheight;   // Length Ratio For Width

         $newheight = $theight;   // Height Is Equal To Max Height

         $newwidth = $currwidth * $zoom;   // Creates The New Width

      } else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)

        $zoom = $twidth / $currwidth;   // Length Ratio For Height

        $newwidth = $twidth;   // Width Is Equal To Max Width

        $newheight = $currheight * $zoom;   // Creates The New Height

      }

      $dimg = imagecreate($newwidth, $newheight);   // Make New Image For Thumbnail

      imagetruecolortopalette($simg, false, 256);   // Create New Color Pallete

      $palsize = ImageColorsTotal($simg);

      for ($i = 0; $i < $palsize; $i++) {   // Counting Colors In The Image

       $colors = ImageColorsForIndex($simg, $i);   // Number Of Colors Used

       ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use

      }

      imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);   // Copy Resized Image To The New Image (So We Can Save It)

      imagejpeg($dimg, "$tdir" . $url);   // Saving The Image

      imagedestroy($simg);   // Destroying The Temporary Image

      imagedestroy($dimg);   // Destroying The Other Temporary Image

     // print 'Image thumbnail created successfully.';   // Resize successful

     print "Image uploaded/changed";

    } else {

      print '<font color="#FF0000">ERROR: Unable to upload image.</font>';   // Error Message If Upload Failed

    }

  } else {

    print '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is ';   // Error Message If Filetype Is Wrong

    print $file_ext;   // Show The Invalid File's Extention

    print '.</font>';

  }

}

$query = "UPDATE `Individual` SET `pic1` = '<a href=\"http://www.jocosingles/chris/$idir$url\" target=\"top\"><img src=\"http://www.jocosingles/chris/$tdir$url\" border=\"0\"></a>' WHERE ind_id = $ind_id";

$result = mysql_query($query,$conn);

 

if($result)

        echo "the query has been successfully executed and database updated";

else 

        echo "error in your sql statement! Your statement is: $query";

                                    

?>

Open in new window

0
 

Author Comment

by:chrisdavis5
ID: 20306822
oh now it says:

error in your sql statement! Your statement is: UPDATE `Individual` SET `pic1` = '' WHERE ind_id =

I want basically to make sure ind_id "3" in the Members table updates in the "Individual" table as ind_id "3" as well...
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306829
yes so basically the problem is there...
So your output didn't include:
<a href=\"http://www.jocosingles/chris/$idir$url\" target=\"top\"><img src=\"http://www.jocosingles/chris/$tdir$url\" border=\"0\"></a>

at all?and also your $ind_id is empty...you need to pass it into your file via either POST or GET...
0
 

Author Comment

by:chrisdavis5
ID: 20306836
No, it just showed a box with a red X in it for the output..only had

error in your sql statement! Your statement is: UPDATE `Individual` SET `pic1` = (WHITE BOX WITH RED X)'' WHERE ind_id =

On my POST on my previous form (upload1.php) the POST is this file (upload5.php)..how would I use GET or POST on the second file to include it?
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306841
yea you are not getting those variables (or passing them in) properly.

is the code for those 2 files long? can you post them?
0
 

Author Comment

by:chrisdavis5
ID: 20306853
HERE IS UPLOAD1.PHP (the form to upload the file)

<?php
// Buzz inet PHPLS03 - Check User Session is set
session_start();
if(!isset($HTTP_SESSION_VARS['test3'])){
      header("Location: login_failed.php");
}
?>
<?php require_once('Connections/test3.php'); ?>
<?php
// Buzz inet PHPLS06 - User Details
session_start();

$colname_rsUserDetails = "-1";
if (isset($_GET['ind_id'])) {
  $colname_rsUserDetails = (get_magic_quotes_gpc()) ? $_GET['ind_id'] : addslashes($_GET['ind_id']);
}
mysql_select_db($database_test3, $test3);
$query_rsUserDetails = sprintf("SELECT * FROM Member WHERE ind_id = %s", $colname_rsUserDetails);
$rsUserDetails = mysql_query($query_rsUserDetails, $test3) or die(mysql_error());
$row_rsUserDetails = mysql_fetch_assoc($rsUserDetails);
$totalRows_rsUserDetails = mysql_num_rows($rsUserDetails);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>

<form enctype="multipart/form-data" action="upload5.php" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="512000" />
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>

<p>&nbsp;</p>
<p>ID: <?php echo $row_rsUserDetails['ind_id']; ?></p>
</body>
</html>
<?php
mysql_free_result($rsUserDetails);
?>


HERE IS THE CODE THAT I CUT/PASTE FROM YOUR PREVIOUS POST (UPLOAD5.PHP)

<?php
//include 'connect1.inc'; // file to connect to the db
$conn = mysql_connect('localhost','heart2_upload','test1');
if(!$conn)
   die("Cannot connect!");
 
$ind_id = $_POST['ind_id'];
$idir = "images/";   // Path To Images Directory
$tdir = "images/thumbs/";   // Path To Thumbnails Directory
$twidth = "300";   // Maximum Width For Thumbnail Images
$theight = "300";   // Maximum Height For Thumbnail Images
 
 
//if (!isset($_GET['subpage'])) {   // Image Upload Form Below
 
  if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') {   // Uploading/Resizing Script
  $url = $_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use
  if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") {
    $file_ext = strrchr($_FILES['imagefile']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php
    $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']);   // Move Image From Temporary Location To Permanent Location
    if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location
      //print 'Image uploaded successfully.<br />';   // Was Able To Successfully Upload Image
      $simg = imagecreatefromjpeg("$idir" . $url);   // Make A New Temporary Image To Create The Thumbanil From
      $currwidth = imagesx($simg);   // Current Image Width
      $currheight = imagesy($simg);   // Current Image Height
      if ($currheight > $currwidth) {   // If Height Is Greater Than Width
         $zoom = $twidth / $currheight;   // Length Ratio For Width
         $newheight = $theight;   // Height Is Equal To Max Height
         $newwidth = $currwidth * $zoom;   // Creates The New Width
      } else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)
        $zoom = $twidth / $currwidth;   // Length Ratio For Height
        $newwidth = $twidth;   // Width Is Equal To Max Width
        $newheight = $currheight * $zoom;   // Creates The New Height
      }
      $dimg = imagecreate($newwidth, $newheight);   // Make New Image For Thumbnail
      imagetruecolortopalette($simg, false, 256);   // Create New Color Pallete
      $palsize = ImageColorsTotal($simg);
      for ($i = 0; $i < $palsize; $i++) {   // Counting Colors In The Image
       $colors = ImageColorsForIndex($simg, $i);   // Number Of Colors Used
       ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use
      }
      imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);   // Copy Resized Image To The New Image (So We Can Save It)
      imagejpeg($dimg, "$tdir" . $url);   // Saving The Image
      imagedestroy($simg);   // Destroying The Temporary Image
      imagedestroy($dimg);   // Destroying The Other Temporary Image
     // print 'Image thumbnail created successfully.';   // Resize successful
     print "Image uploaded/changed";
    } else {
      print '<font color="#FF0000">ERROR: Unable to upload image.</font>';   // Error Message If Upload Failed
    }
  } else {
    print '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is ';   // Error Message If Filetype Is Wrong
    print $file_ext;   // Show The Invalid File's Extention
    print '.</font>';
  }
}
$query = "UPDATE `Individual` SET `pic1` = '<a href=\"http://www.jocosingles/chris/$idir$url\" target=\"top\"><img src=\"http://www.jocosingles/chris/$tdir$url\" border=\"0\"></a>' WHERE ind_id = $ind_id";
$result = mysql_query($query,$conn);
 
if($result)
        echo "the query has been successfully executed and database updated";
else
        echo "error in your sql statement! Your statement is: $query";
                                   
?>
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306868
ok can see a few problems there which i will fix, but firs of all, is this:
$row_rsUserDetails['ind_id']

the variable which contains the id you want to pass to upload5.php?
0
 

Author Comment

by:chrisdavis5
ID: 20306870
yeah that's the variable from the main "Members" table with a PK column called "ind_id" that I want to pass to "upload5.php" so it knows what photo goes with what member..SWEET Thanks for sticking with me on this!!
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306874
try this (this is upload1.php) and use it with the upload5.php which i previously posted..
<?php

// Buzz inet PHPLS03 - Check User Session is set

session_start();

if(!isset($HTTP_SESSION_VARS['test3'])){

      header("Location: login_failed.php");

}

?>

<?php require_once('Connections/test3.php'); ?>

<?php

// Buzz inet PHPLS06 - User Details

session_start();
 

$colname_rsUserDetails = "-1";

if (isset($_GET['ind_id'])) {

  $colname_rsUserDetails = (get_magic_quotes_gpc()) ? $_GET['ind_id'] : addslashes($_GET['ind_id']);

}

mysql_select_db($database_test3, $test3);

$query_rsUserDetails = sprintf("SELECT * FROM Member WHERE ind_id = %s", $colname_rsUserDetails);

$rsUserDetails = mysql_query($query_rsUserDetails, $test3) or die(mysql_error());

$row_rsUserDetails = mysql_fetch_assoc($rsUserDetails);

$totalRows_rsUserDetails = mysql_num_rows($rsUserDetails);

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Untitled Document</title>

</head>
 

<body>
 

<form enctype="multipart/form-data" action="upload5.php" method="POST">

    <input type="hidden" name="MAX_FILE_SIZE" value="512000" />

    <input type="hidden" name="ind_id" value="<?php echo $row_rsUserDetails['ind_id']; ?>" />

    Send this file: <input name="imagefile" type="file" />

    <input type="submit" value="Send File" />

</form>
 

<p>&nbsp;</p>

<p>ID: <?php echo $row_rsUserDetails['ind_id']; ?></p>

</body>

</html>

<?php

mysql_free_result($rsUserDetails);

?>

Open in new window

0
 

Author Comment

by:chrisdavis5
ID: 20306891
Hmm. looks like it added the ID param from the previous page.

error in your sql statement! Your statement is: UPDATE `Individual` SET `pic1` = '' WHERE ind_id = 5

I added a couple of records so now the ID is 5..still doesn't like the sql statement for some reason...
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:chrisdavis5
ID: 20306893
It is not uploading the images either..I have noticed.  maybe that may be the problem..
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306895
little more addition to upload1.php, should work now fingers crossed...
<?php

// Buzz inet PHPLS03 - Check User Session is set

session_start();

if(!isset($HTTP_SESSION_VARS['test3'])){

      header("Location: login_failed.php");

}

?>

<?php require_once('Connections/test3.php'); ?>

<?php

// Buzz inet PHPLS06 - User Details

session_start();
 

$colname_rsUserDetails = "-1";

if (isset($_GET['ind_id'])) {

  $colname_rsUserDetails = (get_magic_quotes_gpc()) ? $_GET['ind_id'] : addslashes($_GET['ind_id']);

}

mysql_select_db($database_test3, $test3);

$query_rsUserDetails = sprintf("SELECT * FROM Member WHERE ind_id = %s", $colname_rsUserDetails);

$rsUserDetails = mysql_query($query_rsUserDetails, $test3) or die(mysql_error());

$row_rsUserDetails = mysql_fetch_assoc($rsUserDetails);

$totalRows_rsUserDetails = mysql_num_rows($rsUserDetails);

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Untitled Document</title>

</head>
 

<body>
 

<form enctype="multipart/form-data" action="upload5.php" method="POST">

    <input type="hidden" name="MAX_FILE_SIZE" value="512000" />

    <input type="hidden" name="subpage" value="upload" />

    <input type="hidden" name="ind_id" value="<?php echo $row_rsUserDetails['ind_id']; ?>" />

    Send this file: <input name="imagefile" type="file" />

    <input type="submit" value="Send File" />

</form>
 

<p>&nbsp;</p>

<p>ID: <?php echo $row_rsUserDetails['ind_id']; ?></p>

</body>

</html>

<?php

mysql_free_result($rsUserDetails);

?>

Open in new window

0
 

Author Comment

by:chrisdavis5
ID: 20306899
oh gosh LOL it's still giving me this:

error in your sql statement! Your statement is: UPDATE `Individual` SET `pic1` = (WHITE BOX with RED X), probably where graphic should be) '' WHERE ind_id = 5
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306902
ok hmm try use the below upload5.php with the posted upload1.php, and let me know if the text:
"The script got to here!" has been outputted to the browser...
<?php

//include 'connect1.inc'; // file to connect to the db

$conn = mysql_connect('localhost','heart2_upload','test1');

if(!$conn)

   die("Cannot connect!");

 

$ind_id = $_POST['ind_id'];

$idir = "images/";   // Path To Images Directory

$tdir = "images/thumbs/";   // Path To Thumbnails Directory

$twidth = "300";   // Maximum Width For Thumbnail Images

$theight = "300";   // Maximum Height For Thumbnail Images

 

 

//if (!isset($_GET['subpage'])) {   // Image Upload Form Below

 

  if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') 

  {   // Uploading/Resizing Script

  	echo "The script got to here!";

  $url = $_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use

  if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") {

    $file_ext = strrchr($_FILES['imagefile']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php

    $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']);   // Move Image From Temporary Location To Permanent Location

    if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location

      //print 'Image uploaded successfully.<br />';   // Was Able To Successfully Upload Image

      $simg = imagecreatefromjpeg("$idir" . $url);   // Make A New Temporary Image To Create The Thumbanil From

      $currwidth = imagesx($simg);   // Current Image Width

      $currheight = imagesy($simg);   // Current Image Height

      if ($currheight > $currwidth) {   // If Height Is Greater Than Width

         $zoom = $twidth / $currheight;   // Length Ratio For Width

         $newheight = $theight;   // Height Is Equal To Max Height

         $newwidth = $currwidth * $zoom;   // Creates The New Width

      } else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)

        $zoom = $twidth / $currwidth;   // Length Ratio For Height

        $newwidth = $twidth;   // Width Is Equal To Max Width

        $newheight = $currheight * $zoom;   // Creates The New Height

      }

      $dimg = imagecreate($newwidth, $newheight);   // Make New Image For Thumbnail

      imagetruecolortopalette($simg, false, 256);   // Create New Color Pallete

      $palsize = ImageColorsTotal($simg);

      for ($i = 0; $i < $palsize; $i++) {   // Counting Colors In The Image

       $colors = ImageColorsForIndex($simg, $i);   // Number Of Colors Used

       ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use

      }

      imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);   // Copy Resized Image To The New Image (So We Can Save It)

      imagejpeg($dimg, "$tdir" . $url);   // Saving The Image

      imagedestroy($simg);   // Destroying The Temporary Image

      imagedestroy($dimg);   // Destroying The Other Temporary Image

     // print 'Image thumbnail created successfully.';   // Resize successful

     print "Image uploaded/changed";

    } else {

      print '<font color="#FF0000">ERROR: Unable to upload image.</font>';   // Error Message If Upload Failed

    }

  } else {

    print '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is ';   // Error Message If Filetype Is Wrong

    print $file_ext;   // Show The Invalid File's Extention

    print '.</font>';

  }

}

$query = "UPDATE `Individual` SET `pic1` = '<a href=\"http://www.jocosingles/chris/$idir$url\" target=\"top\"><img src=\"http://www.jocosingles/chris/$tdir$url\" border=\"0\"></a>' WHERE ind_id = $ind_id";

$result = mysql_query($query,$conn);

 

if($result)

        echo "the query has been successfully executed and database updated";

else

        echo "error in your sql statement! Your statement is: $query";

                                   

?>

Open in new window

0
 

Author Comment

by:chrisdavis5
ID: 20306906
no, I'm getting the same error:

error in your sql statement! Your statement is: UPDATE `Individual` SET `pic1` = '' WHERE ind_id = 5
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306911
ahh i see the problem, change your upload5.php:
<?php

//include 'connect1.inc'; // file to connect to the db

$conn = mysql_connect('localhost','heart2_upload','test1');

if(!$conn)

   die("Cannot connect!");

 

$ind_id = $_POST['ind_id'];

$idir = "images/";   // Path To Images Directory

$tdir = "images/thumbs/";   // Path To Thumbnails Directory

$twidth = "300";   // Maximum Width For Thumbnail Images

$theight = "300";   // Maximum Height For Thumbnail Images

 

 

//if (!isset($_GET['subpage'])) {   // Image Upload Form Below

 

  if (isset($_POST['subpage']) && $_POST['subpage'] == 'upload') 

  {   // Uploading/Resizing Script

  	echo "The script got to here!";

  $url = $_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use

  if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") {

    $file_ext = strrchr($_FILES['imagefile']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php

    $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']);   // Move Image From Temporary Location To Permanent Location

    if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location

      //print 'Image uploaded successfully.<br />';   // Was Able To Successfully Upload Image

      $simg = imagecreatefromjpeg("$idir" . $url);   // Make A New Temporary Image To Create The Thumbanil From

      $currwidth = imagesx($simg);   // Current Image Width

      $currheight = imagesy($simg);   // Current Image Height

      if ($currheight > $currwidth) {   // If Height Is Greater Than Width

         $zoom = $twidth / $currheight;   // Length Ratio For Width

         $newheight = $theight;   // Height Is Equal To Max Height

         $newwidth = $currwidth * $zoom;   // Creates The New Width

      } else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)

        $zoom = $twidth / $currwidth;   // Length Ratio For Height

        $newwidth = $twidth;   // Width Is Equal To Max Width

        $newheight = $currheight * $zoom;   // Creates The New Height

      }

      $dimg = imagecreate($newwidth, $newheight);   // Make New Image For Thumbnail

      imagetruecolortopalette($simg, false, 256);   // Create New Color Pallete

      $palsize = ImageColorsTotal($simg);

      for ($i = 0; $i < $palsize; $i++) {   // Counting Colors In The Image

       $colors = ImageColorsForIndex($simg, $i);   // Number Of Colors Used

       ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use

      }

      imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);   // Copy Resized Image To The New Image (So We Can Save It)

      imagejpeg($dimg, "$tdir" . $url);   // Saving The Image

      imagedestroy($simg);   // Destroying The Temporary Image

      imagedestroy($dimg);   // Destroying The Other Temporary Image

     // print 'Image thumbnail created successfully.';   // Resize successful

     print "Image uploaded/changed";

    } else {

      print '<font color="#FF0000">ERROR: Unable to upload image.</font>';   // Error Message If Upload Failed

    }

  } else {

    print '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is ';   // Error Message If Filetype Is Wrong

    print $file_ext;   // Show The Invalid File's Extention

    print '.</font>';

  }

}

$query = "UPDATE `Individual` SET `pic1` = '<a href=\"http://www.jocosingles/chris/$idir$url\" target=\"top\"><img src=\"http://www.jocosingles/chris/$tdir$url\" border=\"0\"></a>' WHERE ind_id = $ind_id";

$result = mysql_query($query,$conn);

 

if($result)

        echo "the query has been successfully executed and database updated";

else

        echo "error in your sql statement! Your statement is: $query";

                                   

?>

Open in new window

0
 

Author Comment

by:chrisdavis5
ID: 20306916
actually I want to ADD this ind_id = ?? (in this case 5) to the table "Individual" on the same line as the link when adding it..so I can tie it back to the main record in Members..
0
 

Author Comment

by:chrisdavis5
ID: 20306918
sweet getting a little farther:

The script got to here!Image uploaded/changederror in your sql statement! Your statement is: UPDATE `Individual` SET `pic1` (RED X) = '' WHERE ind_id = 4
0
 

Author Comment

by:chrisdavis5
ID: 20306920
It looks like it went on the server at least this time LOL
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306926
ok now you will need to let me know what the RED X 's code is, you can do this by going into the "view source" in your browser, and copy and paste the output sql statement from there.

i think we are close.
0
 

Author Comment

by:chrisdavis5
ID: 20306931
cool beans!  this is the source on the final output page..I uploaded a file named "me_kids_01.jpg" but not sure if it's linking to it properly..it has a Red X in the image spot.  Looks like it didn't update the table as of yet either..I have a line with ind_id of "5" in there...

The script got to here!Image uploaded/changederror in your sql statement! Your statement is: UPDATE `Individual` SET `pic1` = '<a href="http://www.jocosingles/chris/images/me_kids_01.JPG" target="top"><img src="http://www.jocosingles/chris/images/thumbs/me_kids_01.JPG" border="0"></a>' WHERE ind_id = 4
0
 

Author Comment

by:chrisdavis5
ID: 20306938
it appears the images are there but the browser is acting like they're not there..weird.
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306940
no syntax errors there, how about trying this (upload5.php):

let me know the output
<?php

//include 'connect1.inc'; // file to connect to the db

$conn = mysql_connect('localhost','heart2_upload','test1');

if(!$conn)

   die("Cannot connect!");

 

$ind_id = $_POST['ind_id'];

$idir = "images/";   // Path To Images Directory

$tdir = "images/thumbs/";   // Path To Thumbnails Directory

$twidth = "300";   // Maximum Width For Thumbnail Images

$theight = "300";   // Maximum Height For Thumbnail Images

 

 

//if (!isset($_GET['subpage'])) {   // Image Upload Form Below

 

  if (isset($_POST['subpage']) && $_POST['subpage'] == 'upload') 

  {   // Uploading/Resizing Script

  	echo "The script got to here!";

  $url = $_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use

  if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") {

    $file_ext = strrchr($_FILES['imagefile']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php

    $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']);   // Move Image From Temporary Location To Permanent Location

    if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location

      //print 'Image uploaded successfully.<br />';   // Was Able To Successfully Upload Image

      $simg = imagecreatefromjpeg("$idir" . $url);   // Make A New Temporary Image To Create The Thumbanil From

      $currwidth = imagesx($simg);   // Current Image Width

      $currheight = imagesy($simg);   // Current Image Height

      if ($currheight > $currwidth) {   // If Height Is Greater Than Width

         $zoom = $twidth / $currheight;   // Length Ratio For Width

         $newheight = $theight;   // Height Is Equal To Max Height

         $newwidth = $currwidth * $zoom;   // Creates The New Width

      } else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)

        $zoom = $twidth / $currwidth;   // Length Ratio For Height

        $newwidth = $twidth;   // Width Is Equal To Max Width

        $newheight = $currheight * $zoom;   // Creates The New Height

      }

      $dimg = imagecreate($newwidth, $newheight);   // Make New Image For Thumbnail

      imagetruecolortopalette($simg, false, 256);   // Create New Color Pallete

      $palsize = ImageColorsTotal($simg);

      for ($i = 0; $i < $palsize; $i++) {   // Counting Colors In The Image

       $colors = ImageColorsForIndex($simg, $i);   // Number Of Colors Used

       ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use

      }

      imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);   // Copy Resized Image To The New Image (So We Can Save It)

      imagejpeg($dimg, "$tdir" . $url);   // Saving The Image

      imagedestroy($simg);   // Destroying The Temporary Image

      imagedestroy($dimg);   // Destroying The Other Temporary Image

     // print 'Image thumbnail created successfully.';   // Resize successful

     print "Image uploaded/changed";

    } else {

      print '<font color="#FF0000">ERROR: Unable to upload image.</font>';   // Error Message If Upload Failed

    }

  } else {

    print '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is ';   // Error Message If Filetype Is Wrong

    print $file_ext;   // Show The Invalid File's Extention

    print '.</font>';

  }

}

$query = "UPDATE `Individual` SET `pic1` = '<a href=\"http://www.jocosingles/chris/$idir$url\" target=\"top\"><img src=\"http://www.jocosingles/chris/$tdir$url\" border=\"0\"></a>' WHERE ind_id = $ind_id";

$result = mysql_query($query,$conn);

 

if($result)

        echo "the query has been successfully executed and database updated";

else

        echo "error in your sql statement! Your error is: " . mysql_error();

                                   

?>

Open in new window

0
 

Author Comment

by:chrisdavis5
ID: 20306943
ahhah!

The script got to here!Image uploaded/changederror in your sql statement! Your error is: No database selected
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306950
Thats useful!

near the top of this code, replace "your_db" with the database you want to select!
<?php

//include 'connect1.inc'; // file to connect to the db

$conn = mysql_connect('localhost','heart2_upload','test1');

if(!$conn)

   die("Cannot connect!");
 

mysql_select_db("your_db", $conn);

 

$ind_id = $_POST['ind_id'];

$idir = "images/";   // Path To Images Directory

$tdir = "images/thumbs/";   // Path To Thumbnails Directory

$twidth = "300";   // Maximum Width For Thumbnail Images

$theight = "300";   // Maximum Height For Thumbnail Images

 

 

//if (!isset($_GET['subpage'])) {   // Image Upload Form Below

 

  if (isset($_POST['subpage']) && $_POST['subpage'] == 'upload') 

  {   // Uploading/Resizing Script

  	echo "The script got to here!";

  $url = $_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use

  if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") {

    $file_ext = strrchr($_FILES['imagefile']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php

    $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']);   // Move Image From Temporary Location To Permanent Location

    if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location

      //print 'Image uploaded successfully.<br />';   // Was Able To Successfully Upload Image

      $simg = imagecreatefromjpeg("$idir" . $url);   // Make A New Temporary Image To Create The Thumbanil From

      $currwidth = imagesx($simg);   // Current Image Width

      $currheight = imagesy($simg);   // Current Image Height

      if ($currheight > $currwidth) {   // If Height Is Greater Than Width

         $zoom = $twidth / $currheight;   // Length Ratio For Width

         $newheight = $theight;   // Height Is Equal To Max Height

         $newwidth = $currwidth * $zoom;   // Creates The New Width

      } else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)

        $zoom = $twidth / $currwidth;   // Length Ratio For Height

        $newwidth = $twidth;   // Width Is Equal To Max Width

        $newheight = $currheight * $zoom;   // Creates The New Height

      }

      $dimg = imagecreate($newwidth, $newheight);   // Make New Image For Thumbnail

      imagetruecolortopalette($simg, false, 256);   // Create New Color Pallete

      $palsize = ImageColorsTotal($simg);

      for ($i = 0; $i < $palsize; $i++) {   // Counting Colors In The Image

       $colors = ImageColorsForIndex($simg, $i);   // Number Of Colors Used

       ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use

      }

      imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);   // Copy Resized Image To The New Image (So We Can Save It)

      imagejpeg($dimg, "$tdir" . $url);   // Saving The Image

      imagedestroy($simg);   // Destroying The Temporary Image

      imagedestroy($dimg);   // Destroying The Other Temporary Image

     // print 'Image thumbnail created successfully.';   // Resize successful

     print "Image uploaded/changed";

    } else {

      print '<font color="#FF0000">ERROR: Unable to upload image.</font>';   // Error Message If Upload Failed

    }

  } else {

    print '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is ';   // Error Message If Filetype Is Wrong

    print $file_ext;   // Show The Invalid File's Extention

    print '.</font>';

  }

}

$query = "UPDATE `Individual` SET `pic1` = '<a href=\"http://www.jocosingles/chris/$idir$url\" target=\"top\"><img src=\"http://www.jocosingles/chris/$tdir$url\" border=\"0\"></a>' WHERE ind_id = $ind_id";

$result = mysql_query($query,$conn);

 

if($result)

        echo "the query has been successfully executed and database updated";

else

        echo "error in your sql statement! Your error is: " . mysql_error();

                                   

?>

Open in new window

0
 

Author Comment

by:chrisdavis5
ID: 20306961
SWEET you are a genius! LOL that worked and the DB line updated:

<a href="http://www.jocosingles/chris/images/c48222af1f2e.jpeg" target="top"><img src="http://www.jocosingles/chris/images/thumbs/c48222af1f2e.jpeg" border="0"></a>

NOW HAHA how do I pull that link to show the picture on the page?
0
 

Author Comment

by:chrisdavis5
ID: 20306963
Oh could I put that in the CONNECT1.INC file to hide the db connections as well?
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306967
you can try, you have something which works now so try to put the details back into connect1.inc and see if it works.

as for displaying, where do you want it displayed? in upload5.php?
0
 

Author Comment

by:chrisdavis5
ID: 20306972
Displayed probably on the main page I have all the links to change information on..ok I will try to put it in connect1.inc but if it ain't broke LOL..it will be on a localhost internal server anyway eventually so that's probably okay..
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20306978
This will display the image on your main page or any page accessing into the database and retrieving the html code you just updated.

assuming the php script is called main,php, you will need to pass in the id of the ind_id which will be needed for the database, eg:

main.php?id=4


$ind_id = $_REQUEST["id"];

$query = "SELECT pic1 FROM Individual WHERE ind_id = $ind_id";

$conn = mysql_connect('localhost','heart2_upload','test1');

if(!$conn)

   die("Cannot connect!");
 

mysql_select_db("your_db", $conn);
 

$result = mysql_query($query,$conn);

$row = mysql_fetch_array($result);
 

echo $row['pic1'];

Open in new window

0
 

Author Comment

by:chrisdavis5
ID: 20306996
hm...good one chief!  However I'm still getting the box with the red x, like the graphic is there but it's not showing?  I'm using IE mainly and I tried in Firefox as well and there's no picture there..the pic is uploaded to the proper directory but not showing?  Maybe a dir chmod thing??
0
 

Author Comment

by:chrisdavis5
ID: 20307002
I tried to chmod to 777 and get the same thing..it's just a read from the DB..wonder why it's not showing in the browser??
0
 
LVL 21

Accepted Solution

by:
nizsmo earned 500 total points
ID: 20307005
well for that you will have to actually go into the directory on your server and see if the file is there, i am unable to access:
http://www.jocosingles/chris/images/thumbs/c48222af1f2e.jpeg

maybe because it is not public? but that would be why it is a red X instead of your image.
0
 

Author Comment

by:chrisdavis5
ID: 20307022
yeah it's public..

http://jocosingles.com/chris/images/

Oh you know the code in the PHP that references the link. it must have been wrong cause I redid it and it's working now!

THANK YOU SO MUCH FOR hanging in there with me..I learned a lot today!  I wish I could give you more than 500 points..
0
 

Author Closing Comment

by:chrisdavis5
ID: 31409769
Thanks again nizsmo..hope I can learn as much as you!
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20307026
good on you!! :) glad to help! :D
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now