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>
================================================== ====================
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 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);
?>
|