It is quite obvious why the variable you want to have a value doesn't have a value. Its value is not set unless a form is submitted.

$imgfilenameout = "";

This is the value it has before a form is submitted as you can see at the top of your code, nothing.

    Ok, Well I relized that after I posted but I changed to...

    $imgfilenameout = $newfileout;

    And $newfileout; is

    $newfileout = "http://www.groupdominion.com/cp/add" . "/$final_filename";

    When I do a print $newfileout is printed correctly but when I try to add it to the hidden value it does not work.

      Without having seen the new "improved" code you can't just assign a variable to another variable anywhere in your code and expect it to work.

      I assume the code is still at top?
      If so, $newfileout isn't even initialized yet.

      Even if you move it to the bottom, I assume $newfileout is set during form submission again because of the $final_filename, which bring you just as far as you were earlier.

      I'm not sure I get your idea of that hidden field either. If you want to display the image that has been uploaded, mind you, all you do in your code is check the extension, that is -not- a viable way to check for a real image or not, you could just echo the $newfileout and drop that hidden field all together?

      After a successful form submission you could:

      echo "<img src=\"".$newfileout."\" />";
      

        Ok... Well I fixed the quotes around the variable...

        All I get outputted to the database is the address no variable afterward...

        Here is my new code.

        <?php
        if (!function_exists("GetSQLValueString")) {
        function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
        {
          $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
        
          $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
        
          switch ($theType) {
            case "text":
              $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
              break;    
        case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $filenameout = ""; if ($_SERVER['REQUEST_METHOD'] == "POST") { $uploaddir = "."; $pext = getFileExtension($imgfile_name); $pext = strtolower($pext); if (($pext != "jpg") && ($pext != "jpeg")) { print "<h1>ERROR</h1>Image Extension Unknown.<br>"; print "<p>Please upload only a JPEG image with the extension .jpg or .jpeg ONLY<br><br>"; print "The file you uploaded had the following extension: $pext</p>\n"; unlink($imgfile); exit(); } $imgsize = GetImageSize($imgfile); if (($imgsize[0] > 250) || ($imgsize[1] > 200)) { $tmpimg = tempnam("/tmp", "MKUP"); system("djpeg $imgfile >$tmpimg"); system("pnmscale -xy 250 200 $tmpimg | cjpeg -smoo 10 -qual 50 >$imgfile"); unlink($tmpimg); } $final_filename = str_replace(" ", "_", $imgfile_name); $newfile = $uploaddir . "/$final_filename"; $filenameout = $final_filename; if (is_uploaded_file($imgfile)) { if (!copy($imgfile,"$newfile")) { print "Error Uploading File."; exit(); } } unlink($imgfile); $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO c_4Sale (title, address, `description`, units, moRent, appFee, deposit, pets, sqft, bed, bath, petDeposit, petFee, elecPaid, watPaid, sewPaid, yardPaid, parking, features, img_1) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['Address'], "text"), GetSQLValueString($_POST['description'], "text"), GetSQLValueString($_POST['units'], "text"), GetSQLValueString($_POST['moRent'], "text"), GetSQLValueString($_POST['appFee'], "text"), GetSQLValueString($_POST['deposit'], "text"), GetSQLValueString($_POST['pets'], "text"), GetSQLValueString($_POST['sqft'], "text"), GetSQLValueString($_POST['bed'], "text"), GetSQLValueString($_POST['bath'], "text"), GetSQLValueString($_POST['petDeposit'], "text"), GetSQLValueString($_POST['petFee'], "text"), GetSQLValueString($_POST['elecPaid'], "text"), GetSQLValueString($_POST['watPaid'], "text"), GetSQLValueString($_POST['sewPaid'], "text"), GetSQLValueString($_POST['yardPaid'], "text"), GetSQLValueString($_POST['parking'], "text"), GetSQLValueString($_POST['features'], "text"), GetSQLValueString($_POST['img_1'], "text")); mysql_select_db($database_ControlPanel, $ControlPanel); $Result1 = mysql_query($insertSQL, $ControlPanel) or die(mysql_error()); $insertGoTo = "../main.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } $imgfilenameout = "http://www.groupdominion.com/cp/add/" . $filenameout; mysql_select_db($database_ControlPanel, $ControlPanel); $query_Recordset1 = "SELECT * FROM c_4Sale WHERE img_1 = '$imgfilenameout' ORDER BY id ASC"; $Recordset1 = mysql_query($query_Recordset1, $ControlPanel) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?>

          This is what im doing.

          I am putting a form up so someone can upload some information and then a picture. And the address of the picture is stored on the database so it is dynamicly added to the page that calls all of the information.

            Then replace

            GetSQLValueString($_POST['img_1'], "text"));
            

            with

            GetSQLValueString("http://www.groupdominion.com/cp/add/" . $filenameout));
            

            which should store the filepath + name in the img_1 field in your database.

            This is of course assuming $filenameout get its value in the above if statement.

              OK that worked. Thanks!

              The weird thing is, before I started messing with it the upload code worked... now it doesn't.. haha. But thats a different story.

              Thanks again!

                After $pext = getFileExtension($imgfile_name);

                Put in:

                echo "My filename is: ".$imgfile_name;
                exit;

                See if it outputs anything when you upload the file.

                  Yes it outputs the correct filename.

                  It does upload something... but when I open it there is a img error but when I go to the FTP it has the file name with 0kb...

                  Its like it added the file name only.

                  BUT if I take out the resize code it uploads the whole picture but I would really like the resize ability.

                    Check your PHP error log and see what it says when trying to call those system commands.

                      Umm... This is gonna sound like a newbie question but where do I check the logs?

                        I don't know your server so I can't give you a definite answer on that.

                        Check where php.ini or apaches httpd.conf is set to write logs.

                        One guess could be that the system commands you are calling doesn't exist on the server you are on. But really, it could be anything, your best bet is those logs.

                          Write a Reply...