Jump to content

help please


tangolik

Recommended Posts

Hi all, I have this add items page what i wanna do is, when I am adding items to my inventory, I want to be able see the images  in pull down menus for main_image, small image and thumb sections. this will help avoid any misspelling and save alo of entry time( which they are already on server side in a folder called "image". someone here on this suggested me use some code but i cant figure it oue how to work it. i am posting both, my add item page code and the suggested ( and tried to mimic my way) code. thanks in advance for any help.

 

my additem page code;

 

<?php require_once('Connections/connLocal.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 rings (model_number, dia_shape, VintageOrClassic, metal_type, title, price, appraisal, `description`, thumb, main_image_1, main_image_2, main_image_3, main_image_4, main_image_5, sm_img_1, sm_img_2, sm_img_3, sm_img_4, sm_img_5) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['model_number'], "text"),
                       GetSQLValueString($_POST['dia_shape'], "text"),
                       GetSQLValueString($_POST['VintageOrClassic'], "text"),
                       GetSQLValueString($_POST['metal_type'], "text"),
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['price'], "text"),
                       GetSQLValueString($_POST['appraisal'], "text"),
                       GetSQLValueString($_POST['description'], "text"),
                       GetSQLValueString($_POST['thumb'], "text"),
				   GetSQLValueString($_POST['main_image_1'], "text"),
                       GetSQLValueString($_POST['main_image_2'], "text"),
                       GetSQLValueString($_POST['main_image_3'], "text"),
                       GetSQLValueString($_POST['main_image_4'], "text"),
                       GetSQLValueString($_POST['main_image_5'], "text"),
                       GetSQLValueString($_POST['sm_img_1'], "text"),
                       GetSQLValueString($_POST['sm_img_2'], "text"),
                       GetSQLValueString($_POST['sm_img_3'], "text"),
                       GetSQLValueString($_POST['sm_img_4'], "text"),
                       GetSQLValueString($_POST['sm_img_5'], "text"));

  mysql_select_db($database_connLocal, $connLocal);
  $Result1 = mysql_query($insertSQL, $connLocal) or die(mysql_error());

  $insertGoTo = "additems.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>Add Items</title>
</head>

<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <table align="center" bgcolor="#66FF66">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Model_number:</td>
      <td><input type="text" name="model_number" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Dia_shape:</td>
      <td><select name="dia_shape">
        <option value="round" <?php if (!(strcmp("round", ""))) {echo "SELECTED";} ?>>Round</option>
        <option value="princess" <?php if (!(strcmp("princess", ""))) {echo "SELECTED";} ?>>Princess</option>
        <option value="emerald" <?php if (!(strcmp("emerald", ""))) {echo "SELECTED";} ?>>Emerald</option>
        <option value="radiant" <?php if (!(strcmp("radiant", ""))) {echo "SELECTED";} ?>>Radiant</option>
        <option value="asscher" <?php if (!(strcmp("asscher", ""))) {echo "SELECTED";} ?>>Asscher</option>
        <option value="oval" <?php if (!(strcmp("oval", ""))) {echo "SELECTED";} ?>>Oval</option>
        <option value="pear" <?php if (!(strcmp("pear", ""))) {echo "SELECTED";} ?>>Pear</option>
        <option value="marquise" <?php if (!(strcmp("marquise", ""))) {echo "SELECTED";} ?>>Marquise</option>
        <option value="heart" <?php if (!(strcmp("heart", ""))) {echo "SELECTED";} ?>>Heart</option>
        <option value="cushion" <?php if (!(strcmp("cushion", ""))) {echo "SELECTED";} ?>>Cushion</option>
      </select>      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Vintage/Classic:</td>
      <td><select name="VintageOrClassic">
        <option value="vintage" <?php if (!(strcmp("vintage", ""))) {echo "SELECTED";} ?>>Vintage</option>
        <option value="classic" <?php if (!(strcmp("classic", ""))) {echo "SELECTED";} ?>>Classic</option>
      </select>      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Metal_type:</td>
      <td><select name="metal_type">
        <option value="platinum" <?php if (!(strcmp("platinum", ""))) {echo "SELECTED";} ?>>Platinum</option>
        <option value="14K white gold" <?php if (!(strcmp("14K white gold", ""))) {echo "SELECTED";} ?>>14K White Gold</option>
        <option value="14K yellow gold" <?php if (!(strcmp("14K yellow gold", ""))) {echo "SELECTED";} ?>>14K Yellow Gold</option>
        <option value="18K white gold" <?php if (!(strcmp("18K white gold", ""))) {echo "SELECTED";} ?>>18K White Gold</option>
        <option value="18K yellow gold" <?php if (!(strcmp("18K yellow gold", ""))) {echo "SELECTED";} ?>>18K Yellow Gold</option>
      </select>      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Title:</td>
      <td><select name="title">
        <option value="diamond engagement ring" <?php if (!(strcmp("diamond engagement ring", ""))) {echo "SELECTED";} ?>>Diamond Engagement Ring</option>
      </select>      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Price:</td>
      <td><input type="text" name="price" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Appraisal:</td>
      <td><input type="text" name="appraisal" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Description:</td>
      <td><textarea name="description" cols="50" rows="5" wrap="virtual"></textarea></td>  
      </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Thumb</td>
      <td><input type="text" name="thumb" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Main_image_1:</td>
      <td><input type="text" name="main_image_1" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Main_image_2:</td>
      <td><input type="text" name="main_image_2" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Main_image_3:</td>
      <td><input type="text" name="main_image_3" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Main_image_4:</td>
      <td><input type="text" name="main_image_4" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Main_image_5:</td>
      <td><input type="text" name="main_image_5" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Sm_img_1:</td>
      <td><input type="text" name="sm_img_1" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Sm_img_2:</td>
      <td><input type="text" name="sm_img_2" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Sm_img_3:</td>
      <td><input type="text" name="sm_img_3" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Sm_img_4:</td>
      <td><input type="text" name="sm_img_4" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Sm_img_5:</td>
      <td><input type="text" name="sm_img_5" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"> </td>
      <td><input type="submit" value="Insert record" />
      <label>
      <input type="reset" name="Reset" id="button" value="Reset" />
      </label></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
</body>
</html>

 

and the suggested code

<?php 
require_once('Connections/connLocal.php');

  $dir = glob('image/*.jpg');
  foreach ($dir as $file) {
    $bumu = "INSERT INTO rings ('thumb') VALUES ('images/$file');"
    if (mysql_query($bumu)) {
      echo "image/$file added to db.<br />";
    }
  }

?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.