Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
| Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 3rd, 2006, 02:00 AM
Registered User
Join Date: Mar 2006
Location: Woodbury, CT, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default BLOB - Uploading images into a database

I am kinda new at this whole PHP thing but I am jumping right in, I have developed a website that has customers - employees - parts - products & all my data is stored in a MySql Database. I am trying to upload images into my database and from the reading I have done I know the data table needs to be "BLOB" format (bin_data)

The problem I am having is this, I do not write raw code, like I said I am very new at this but I am learning fast......I am using Dreamweaver MX as well as the PHP/MySql for dummies book I bought. now the trouble I am having is that when I created my form to add a new product it wants to upload the images as "text" which only stores the path and if I change the values to "bin_data" or "BLOB" instead of "text" then the page will not load and I get errors. I have been all over the net looking for help and I have tried other peoples code but nothing seems to work with the code I worte. everything in my code works PERFICT except I can not get it to upload the images into the database. If ANYONE uses Dreamweaver MX or thinks they can incorperate some of thier own code into this PLEASE PLEASE help me!!

================================================== ====================
<center>Here is the section code in question:</center>
================================================== ====================
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  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 products (model, hydraulic_type, length, description, price, image, image_thumb, short_description) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['model'], "text"),
                       GetSQLValueString($_POST['hydraulic_type'], "text"),
                       GetSQLValueString($_POST['length'], "text"),
                       GetSQLValueString($_POST['desricption'], "text"),
                       GetSQLValueString($_POST['price'], "text"),
                       GetSQLValueString($_POST['image'], "text"),
                       GetSQLValueString($_POST['image_thumb'], "text"),
                       GetSQLValueString($_POST['short_description'], "text"));

  mysql_select_db($database_HPC_products, $HPC_products);
  $Result1 = mysql_query($insertSQL, $HPC_products) or die(mysql_error());

  $insertGoTo = "index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  header(sprintf("Location: %s", $insertGoTo));

mysql_select_db($database_HPC_products, $HPC_products);
$query_RSadd_product = "SELECT * FROM products";
$RSadd_product = mysql_query($query_RSadd_product, $HPC_products) or die(mysql_error());
$row_RSadd_product = mysql_fetch_assoc($RSadd_product);
$totalRows_RSadd_product = mysql_num_rows($RSadd_product);

Old March 10th, 2006, 09:02 PM
Friend of Wrox
Join Date: Dec 2004
Location: London, London, United Kingdom.
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts

just a small something: Most developpers try to go around storing pictures in database. Mainly because the transfer of a picture out of a database is taking absolutely ages (on the process level) and therfor it will slow down the server.

What most developpers try to do when possible is to store that picture somewhere safe (keep the picture name and location in the database).

I use a system where the pictures are stored away from the website folder, and I only move them into the /website/pictures when the pictures are requested. I have a "bot" who does the clean up every 2 hours to stop links.

Obviously if you need to store picture for security into a database ignore the above.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Uploading & retriving Images From Database aaaboye Classic ASP Basics 1 February 20th, 2007 04:03 PM
Retrieving and Uploading Images in Database vijay_83 ASP.NET 2.0 Professional 1 October 4th, 2006 03:25 PM
problem with uploading blob data to MySQL DB kyle_shea PHP Databases 1 March 8th, 2005 06:15 PM
Problem inserting blob data/uploading file - MySQL kyle_shea Beginning PHP 2 February 15th, 2005 10:18 AM
Uploading images to a database vivi Classic ASP Basics 3 October 30th, 2003 10:14 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.