HELLO THERE!
I´m trying to update an image field from an update statement and a form. the code is:
SET TEXT PARAMETERS AND SCAPE SPECIAL CHARACTERS
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_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE pro SET cliente=%s, clave=%s, foto=%s, precio=%s WHERE id=%s",
GetSQLValueString($_POST['cliente'], "text"),
GetSQLValueString($_POST['clave'], "text"),
GetSQLValueString(file_get_contents($_FILES['foto']['tmp_name']), "text"),
GetSQLValueString($_POST['precio'], "double"),
GetSQLValueString($_POST['id'], "int"));
mysql_select_db($database_se, $se);
$Result1 = mysql_query($updateSQL, $se) or die(mysql_error());
$updateGoTo = "test.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
DEFINE DATABASE AND SELECT TABLES
$colname_RecordsetPro = "1";
if (isset($_GET['id'])) {
$colname_RecordsetPro = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_se, $se);
$query_RecordsetPro = sprintf("SELECT * FROM pro WHERE id = %s", $colname_RecordsetPro);
$RecordsetPro = mysql_query($query_RecordsetPro, $se) or die(mysql_error());
$row_RecordsetPro = mysql_fetch_assoc($RecordsetPro);
$totalRows_RecordsetPro = mysql_num_rows($RecordsetPro);
AND THEN, THE FORM SO USERS CAN SEND:
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
Id: <?php echo $row_RecordsetPro['id']; ?>
Cliente: <input name="cliente" type="text" class="form" value="<?php echo $row_RecordsetPro['cliente']; ?>" size="32">
Clave: <input name="clave" type="text" class="form" value="<?php echo $row_RecordsetPro['clave']; ?>" size="32">
Foto: <input name="foto" type="file" class="form" size="32" maxlength="30000">
Precio: <input name="precio" type="text" class="form" value="<?php echo $row_RecordsetPro['precio']; ?>" size="32"><
<input type="submit" class="form" value="Update record">
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="id" value="<?php echo $row_RecordsetPro['id']; ?>"> </form>
EVERYTHING works fine, except that I get no image uploaded to the server (field goes blank), I get no errors, and I´m a little bit of stuck.
I appreciate your help
THANX!