I am making an admin product form where my client can insert product title, description and thumbnail into the mysql database table which displays on my product page. They want to be able to add products on their own so I need to be able to let them to do this. I am somewhat new to php mysql so sorry if this is pretty basic but i can't get the image insert to work in my form, the title and description work great and are displaying well.

any help would be greatly appreciated.

<?php require_once('Connections/asiadirect.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 products (productTitle, productDescription, productThumb) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['product'], "text"),
                       GetSQLValueString($_POST['description'], "text"),
                       GetSQLValueString($_POST['productThumb'], "text"));

  mysql_select_db($database_asiadirect, $asiadirect);
  $Result1 = mysql_query($insertSQL, $asiadirect) or die(mysql_error());

  $insertGoTo = "firepits.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<!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>Untitled Document</title>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationTextarea.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationTextarea.css" rel="stylesheet" type="text/css" />
</head>

<body>


<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">
  <table width="708" border="1">
    <tr>
      <td width="184">PRODUCT TITLE</td>
      <td width="508"><span id="productName">
      <label for="product"></label>
      <input type="text" name="product" id="product" />
      <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldMinCharsMsg">Minimum number of characters not met.</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span></span></td>
    </tr>
    <tr>
      <td height="176">PRODUCT DESCRIPTION</td>
      <td><span id="productDescription">
      <label for="description"></label>
      <textarea name="description" id="description" cols="70" rows="8"></textarea>
      <span class="textareaRequiredMsg">A value is required.</span><span class="textareaMaxCharsMsg">Exceeded maximum number of characters.</span><span class="textareaMinCharsMsg">Minimum number of characters not met.</span></span></td>
    </tr>
    <tr>
      <td>PRODUCT THUMBNAIL</td>
      <td bgcolor="#FFFFFF"><label for="productThumb"></label>
      <input type="file" name="productThumb" id="productThumb" /></td>
    </tr>
  </table>
  <input type="submit" name="Submit" id="Submit" value="Submit" />
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("productName", "none", {validateOn:["blur"], minChars:1, maxChars:20, hint:"Product Name"});
var sprytextarea1 = new Spry.Widget.ValidationTextarea("productDescription", {validateOn:["blur"], maxChars:200, minChars:1, hint:"Product Description"});
</script>
</body>
</html>

Ok so what you want to do is first upload the image with the script. Just make him select the image file ect and then when he submits that form. Have it put the link to that image onto a variable. Then insert the variable data (the image link) into the database. then echo it out via

echo '<img href="THE LINK" />';

Here is a link to a tutorial i found.. its for a shopping cart system but you can use it for yours.

http://hockinson.com/index.php?s=37

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.