5 Replies Latest reply: Sep 25, 2014 2:03 PM by bregent RSS

    Code wont work when trying to upload image!

    Max Resnikoff Community Member

      My Code wont work when I try to upload an image to mysql. (Field in mysql is BLOB)

       

       

       

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <html xmlns="http://www.w3.org/1999/xhtml">

      <head>

      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

      <title>insert</title>

      <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>

      <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />

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

      <?php

      if (!function_exists("GetSQLValueString")) {

      function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

      {

        if (PHP_VERSION < 6) {

          $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;

      }

      }

       

      $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 databaseimage (name, image) VALUES (%s, %s)",

                             GetSQLValueString($_POST['name'], "text"),

                             GetSQLValueString($_POST['image'], "double"));

       

        mysql_select_db($database_drama_database, $drama_database);

        $Result1 = mysql_query($insertSQL, $drama_database) or die(mysql_error());

      }

       

      mysql_select_db($database_drama_database, $drama_database);

      $query_image = "SELECT * FROM databaseimage";

      $image = mysql_query($query_image, $drama_database) or die(mysql_error());

      $row_image = mysql_fetch_assoc($image);

      $totalRows_image = mysql_num_rows($image);

      ?>

       

      </head>

       

      <body>

      <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">

      Name:  <span id="sprytextfield1">

        <label for="name"></label>

        <input type="text" name="name" id="name" />

        <span class="textfieldRequiredMsg">A value is required.</span></span>

        <p>

          <label for="image"></label>

          <input type="file" name="image" id="image" />

        </p>

        <p>

          <input type="submit" name="Upload" id="Upload" value="Upload" />

        </p>

        <input type="hidden" name="MM_insert" value="form1" />

      </form>

      <script type="text/javascript">

      var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");

      </script>

      </body>

      </html>

      <?php

      mysql_free_result($image);

      ?>

       

       

      Any help would be very much appreciated!