MFO Posted November 16, 2007 Share Posted November 16, 2007 I tried to change input type in a form from "text" to "file" (so I can find pics easier) in Dreamweaver. It didn't work. It lets me find the pic, but then no value is passed. From <input type="text" name="image" value="image/" size="32" /> To <input type="file" name="image" value="image/" size="32" /> Thanks for your help! Entire Page Source: <?php require_once('Connections/connDB.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 products (prodItemNum, productName, price, `description`, inventory, vendorID, categoryID, image, onSale) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['prodItemNum'], "text"), GetSQLValueString($_POST['productName'], "text"), GetSQLValueString($_POST['price'], "double"), GetSQLValueString($_POST['description'], "text"), GetSQLValueString($_POST['inventory'], "text"), GetSQLValueString($_POST['vendorID'], "int"), GetSQLValueString($_POST['categoryID'], "int"), GetSQLValueString($_POST['image'], "text"), GetSQLValueString(isset($_POST['onSale']) ? "true" : "", "defined","1","0")); mysql_select_db($database_connDB, $connDB); $Result1 = mysql_query($insertSQL, $connDB) or die(mysql_error()); $insertGoTo = "manager.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_connDB, $connDB); $query_rsCategories = "SELECT * FROM categories ORDER BY categoryName ASC"; $rsCategories = mysql_query($query_rsCategories, $connDB) or die(mysql_error()); $row_rsCategories = mysql_fetch_assoc($rsCategories); $totalRows_rsCategories = mysql_num_rows($rsCategories); mysql_select_db($database_connDB, $connDB); $query_rsVendors = "SELECT * FROM vendors ORDER BY vendorName ASC"; $rsVendors = mysql_query($query_rsVendors, $connDB) or die(mysql_error()); $row_rsVendors = mysql_fetch_assoc($rsVendors); $totalRows_rsVendors = mysql_num_rows($rsVendors); ?><!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=iso-8859-1" /> <title>Untitled Document</title> <style type="text/css"> <!-- .style1 {font-size: 9px} --> </style> </head> <body> <?php echo $row_rsCategories['']; ?> <?php echo $row_rsVendors['']; ?> <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1"> <table align="center"> <tr valign="baseline"> <td nowrap="nowrap" align="right">Item#:</td> <td><input type="text" name="prodItemNum" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Name:</td> <td><input type="text" name="productName" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Price:</td> <td><input type="text" name="price" value="Not Entered" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right" valign="top">Description:</td> <td> <textarea name="description" cols="50" rows="5" value=""></textarea><br /> <span class="style1"><br><br>Also available in <br /><br><br> <font size=3>Related Item(s): <a href="details.php?prodID=&vendID=">Rocker Recliner</a></font></span><br /> </p></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Inventory:</td> <td valign="baseline"><table> <tr> <td><input type="radio" name="inventory" value="In Stock" checked /> In Stock</td> </tr> <tr> <td><input type="radio" name="inventory" value="Out of Stock" /> Out of Stock</td> </tr> </table></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">VendorID:</td> <td><select name="vendorID"> <?php do { ?> <option value="<?php echo $row_rsVendors['vendorID']?>" ><?php echo $row_rsVendors['vendorName']?></option> <?php } while ($row_rsVendors = mysql_fetch_assoc($rsVendors)); ?> </select> </td> </tr> <tr> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">CategoryID:</td> <td><select name="categoryID"> <?php do { ?> <option value="<?php echo $row_rsCategories['categoryID']?>" ><?php echo $row_rsCategories['categoryName']?></option> <?php } while ($row_rsCategories = mysql_fetch_assoc($rsCategories)); ?> </select> </td> </tr> <tr> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Image File:</td> <td><input type="file" name="image" value="image/" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">On Sale:</td> <td><input type="checkbox" name="onSale" value="" /></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="MM_insert" value="form1" /> </form> <p> </p> </body> </html> <?php mysql_free_result($rsCategories); mysql_free_result($rsVendors); ?> Quote Link to comment https://forums.phpfreaks.com/topic/77651-change-input-type-from-text-to-file-in-dreamweaver/ Share on other sites More sharing options...
themistral Posted December 9, 2007 Share Posted December 9, 2007 Try adding enctype="multipart/form-data" to the form tag <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1" enctype="multipart/form-data"> Quote Link to comment https://forums.phpfreaks.com/topic/77651-change-input-type-from-text-to-file-in-dreamweaver/#findComment-410271 Share on other sites More sharing options...
saadshams Posted December 30, 2007 Share Posted December 30, 2007 If i am not wrong you are trying to upload files. If then google "PHP Uploage Files". The strategy is usually to save filename (with path, depends), and a separate code to deal with the upload of the file to a specific folder (note, create this folder yourself on the server, PHP will not create it for you). add this after GetSQLValueString function if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $uploaddir = 'images/'; $uploadfile = $uploaddir . basename($_FILES['image]['name']); move_uploaded_file($_FILES['image]['tmp_name'], $uploadfile); $_POST['image'] = basename($_FILES['image]['name']); //filename of the uploaded file } //the rest is okay $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 (prodItemNum, productName, price, `description`, inventory, vendorID, categoryID, image, onSale) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)", Quote Link to comment https://forums.phpfreaks.com/topic/77651-change-input-type-from-text-to-file-in-dreamweaver/#findComment-425622 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.