Jump to content

images uploaded with php form dont display


kevy

Recommended Posts

Hi,

 

My php form, using a "file" input, seems to only store the image name in the database. I thought that by changing the file type, it would upload the full filename, however I don't know which file type to use other than "text".

 

When I display the table data, if the intended file was localhost\antiques\images\image1.jpg all that will show is the text "image1". So hopefully when this problem of uploading the full filepath is corrected, will the images begin to show?

 

Thanks!

I apologize ahead of time for the length of this code.. Why is it that when input type = file, it doesn't upload the full path to the database field? Also, I'm using dreamweaver, which explains the length of the code and the possible confusion.

 

<?php require_once('../Connections/antiques.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $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 itemdetails (`CatId`, `SubId`, `SubName`, `ItemNum`, `Date`, `ItemName`, `Description`, `Condition`, `Provenance`, `Authenticity`, `SellingPrice`, `Image1`, `Image2`, `Image3`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['CatId'], "int"),
                       GetSQLValueString($_POST['SubId'], "int"),
                       GetSQLValueString($_POST['SubName'], "text"),
                       GetSQLValueString($_POST['ItemNum'], "int"),
                       GetSQLValueString($_POST['Date'], "text"),
                       GetSQLValueString($_POST['ItemName'], "text"),
                       GetSQLValueString($_POST['Description'], "text"),
                       GetSQLValueString($_POST['Condition'], "text"),
                       GetSQLValueString($_POST['Provenance'], "text"),
                       GetSQLValueString($_POST['Authenticity'], "text"),
                       GetSQLValueString($_POST['SellingPrice'], "int"),
                       GetSQLValueString($_POST['Image1'], "text"),
                       GetSQLValueString($_POST['Image2'], "text"),
                       GetSQLValueString($_POST['Image3'], "text"));

  mysql_select_db($database_antiques, $antiques);
  $Result1 = mysql_query($insertSQL, $antiques) or die(mysql_error());

  $insertGoTo = "index.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>
</head>

<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">CatId:</td>
      <td><select name="CatId">
        <option value="1" <?php if (!(strcmp(1, ""))) {echo "SELECTED";} ?>>Furniture</option>
        <option value="2" <?php if (!(strcmp(2, ""))) {echo "SELECTED";} ?>>Housewares</option>
        <option value="3" <?php if (!(strcmp(3, ""))) {echo "SELECTED";} ?>>Jewelry</option>
      </select>      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">SubId:</td>
      <td><select name="SubId">
        <option value="1" <?php if (!(strcmp(1, ""))) {echo "SELECTED";} ?>>Tables</option>
        <option value="2" <?php if (!(strcmp(2, ""))) {echo "SELECTED";} ?>>Chairs</option>
        <option value="3" <?php if (!(strcmp(3, ""))) {echo "SELECTED";} ?>>Silverware</option>
        <option value="4" <?php if (!(strcmp(4, ""))) {echo "SELECTED";} ?>>Lamps</option>
        <option value="5" <?php if (!(strcmp(5, ""))) {echo "SELECTED";} ?>>Necklaces</option>
        <option value="6" <?php if (!(strcmp(6, ""))) {echo "SELECTED";} ?>>Bracelets</option>
      </select>      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">SubName:</td>
      <td><select name="SubName">
        <option value="Tables" <?php if (!(strcmp("Tables", ""))) {echo "SELECTED";} ?>>Tables</option>
        <option value="Chairs" <?php if (!(strcmp("Chairs", ""))) {echo "SELECTED";} ?>>Chairs</option>
        <option value="Silverware" <?php if (!(strcmp("Silverware", ""))) {echo "SELECTED";} ?>>Silverware</option>
        <option value="Lamps" <?php if (!(strcmp("Lamps", ""))) {echo "SELECTED";} ?>>Lamps</option>
        <option value="Necklaces" <?php if (!(strcmp("Necklaces", ""))) {echo "SELECTED";} ?>>Necklaces</option>
        <option value="Bracelets" <?php if (!(strcmp("Bracelets", ""))) {echo "SELECTED";} ?>>Bracelets</option>
      </select>      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Date:</td>
      <td><input type="text" name="Date" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">ItemName:</td>
      <td><input type="text" name="ItemName" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right" valign="top">Description:</td>
      <td><textarea name="Description" cols="50" rows="5"></textarea>      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right" valign="top">Condition:</td>
      <td><textarea name="Condition" cols="50" rows="5"></textarea>      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right" valign="top">Provenance:</td>
      <td><textarea name="Provenance" cols="50" rows="5"></textarea>      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right" valign="top">Authenticity:</td>
      <td><textarea name="Authenticity" cols="50" rows="5"></textarea>      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">SellingPrice:</td>
      <td><input type="text" name="SellingPrice" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Image1:</td>
      <td><input type="file" name="Image1" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Image2:</td>
      <td><input type="file" name="Image2" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Image3:</td>
      <td><input type="file" name="Image3" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"> </td>
      <td><input type="submit" value="Insert record" /></td>
    </tr>
  </table>
  <input type="hidden" name="ItemNum" value="" />
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
<p> </p>
<p> </p>
</body>
</html>

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.