title: Upload and Resize Your Image link to mysql
body: <p>I got this script from the net and changed few things to suit my needs but whatever I do I cannot put the link into my DB.</p>
  
  <pre><code>&lt;html&gt;
      &lt;body&gt;
      &lt;h2&gt;Upload and Resize Your Image&lt;/h2&gt;
      &lt;?php
      // index.php
      function generate_resized_image(){
          $max_dimension = 800; // Max new width or height, can not exceed this value.
          $dir = "../../upload123/"; // Directory to save resized image. (Include a trailing slash - /)
          // Collect the post variables.
          $postvars = array(
              "image"    =&gt; trim($_FILES["image"]["name"]),
              "image_tmp"    =&gt; $_FILES["image"]["tmp_name"],
              "image_size"    =&gt; (int)$_FILES["image"]["size"],
              "image_max_width"    =&gt; (int)$_POST["image_max_width"],
              "image_max_height"   =&gt; (int)$_POST["image_max_height"]
          );
          // Array of valid extensions.
          $valid_exts = array("jpg","jpeg","gif","png");
          // Select the extension from the file.
          $ext = end(explode(".",strtolower(trim($_FILES["image"]["name"]))));
          // Check not larger than 175kb.
          if($postvars["image_size"] &lt;= 1048576){
              // Check is valid extension.
              if(in_array($ext,$valid_exts)){
                  if($ext == "jpg" || $ext == "jpeg"){
                      $image = imagecreatefromjpeg($postvars["image_tmp"]);
                  }
                  else if($ext == "gif"){
                      $image = imagecreatefromgif($postvars["image_tmp"]);
                  }
                  else if($ext == "png"){
                      $image = imagecreatefrompng($postvars["image_tmp"]);
                  }
                  // Grab the width and height of the image.
                  list($width,$height) = getimagesize($postvars["image_tmp"]);
                  // If the max width input is greater than max height we base the new image off of that, otherwise we
                  // use the max height input.
                  // We get the other dimension by multiplying the quotient of the new width or height divided by
                  // the old width or height.
                  if($postvars["image_max_width"] &gt; $postvars["image_max_height"]){
                      if($postvars["image_max_width"] &gt; $max_dimension){
                          $newwidth = $max_dimension;
                      } else {
                          $newwidth = $postvars["image_max_width"];
                      }
                      $newheight = ($newwidth / $width) * $height;
                  } else {
                      if($postvars["image_max_height"] &gt; $max_dimension){
                          $newheight = $max_dimension;
                      } else {
                          $newheight = $postvars["image_max_height"];
                      }
                      $newwidth = ($newheight / $height) * $width;
                  }
                  // Create temporary image file.
                  $tmp = imagecreatetruecolor($newwidth,$newheight);
                  // Copy the image to one with the new width and height.
                   imagecopyresampled($tmp,$image,0,0,0,0,$newwidth,$newheight,$width,$height);
                  // Create random 4 digit number for filename.
                  $rand = rand(1000,9999);
                  $filename = $dir.$rand.$postvars["image"];
                  // Create image file with 100% quality.
                  imagejpeg($tmp,$filename,100);
                  return "&lt;strong&gt;Image Preview:&lt;/strong&gt;&lt;br/&gt;
                      &lt;img src=\"".$filename."\" border=\"0\" title=\"Resized  Image Preview\" style=\"padding: 4px 0px 4px 0px;background-color:#e0e0e0\" /&gt;&lt;br/&gt;
                      Resized image successfully generated. &lt;a href=\"".$filename."\" target=\"_blank\"  name=\"Download your resized image now!\"&gt;Click here to download your image.&lt;/a&gt;";
                  imagedestroy($image);
                  imagedestroy($tmp);
              } else {
                  return "File size too large. Max allowed file size is 175kb.";
              }
          } else {
              return "Invalid file type. You must upload an image file. (jpg, jpeg, gif, png).";
          }
      }
      if(isset($_GET["do"])){
          if($_GET["do"] == "upload"){
             $upload_and_resize = generate_resized_image();
          } else {
          $upload_and_resize = "";
      }
      } else {
          $upload_and_resize = "";
      }
      ?&gt;
  
                  &lt;form action="./upload.php?do=upload" method="post" enctype="multipart/form-data"&gt;
                      &lt;table width="100%" align="center" border="0" cellpadding="2" cellspacing="0"&gt;
                      &lt;tr&gt;
                          &lt;td align="left" width="100"&gt;Max Width:&lt;/td&gt;
                          &lt;input name="image_max_width" type="hidden" id="hiddenField" value="400" /&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td align="left"&gt;Image:&lt;/td&gt;
                          &lt;td align="left"&gt;&lt;input type="file" name="image" size="40" /&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td align="left" colspan="2"&gt;
                              &lt;ol style="margin:0;padding:3px 0px 3px 15px"&gt;
                                  &lt;li&gt;Max file size: 175 KB.&lt;/li&gt;
                                  &lt;li&gt;Allowed extensions: jpg, jpeg, gif, png.&lt;/li&gt;
                                  &lt;li&gt;Max Dimension: &lt;em&gt;800&lt;/em&gt;px.&lt;/li&gt;
                              &lt;/ol&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td align="left" colspan="2"&gt;
                              &lt;input type="submit" name="submit" value="Submit!" class="submit" /&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/form&gt;
  
              &lt;div id="upload"&gt;
                  &lt;?php echo $upload_and_resize; ?&gt;
              &lt;/div&gt;
          &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>So I tried various positions but none helped this is what I need to put in my Db which is simple table 1- ID 2- slime (slime is where the image link goes)</p>
  
  <pre><code>    $filenamex=$filename;
      $con = mysql_connect("localhost","USER","PASS");
      if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
  
      mysql_select_db("myDB", $con);
  
      $sql="INSERT INTO acc1 (slime)
      VALUES
      ('$filenamex')";
  
      if (!mysql_query($sql,$con))
        {
        die('Error: ' . mysql_error());
        }
  
      mysql_close($con)
  </code></pre>