Ciao, il codice che uso per l'inserimento è:
<? 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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["insert"])) && ($HTTP_POST_VARS["insert"] == "formprod")) {
$insertSQL = sprintf("INSERT INTO prodotti (titolo, testo, foto, prezzo, sitoproduttore, codice) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['titolo'], "text"),
GetSQLValueString($HTTP_POST_VARS['testo'], "text"),
GetSQLValueString($HTTP_POST_VARS['foto'], "text"),
GetSQLValueString($HTTP_POST_VARS['prezzo'], "double"),
GetSQLValueString($HTTP_POST_VARS['produttore'], "text"),
GetSQLValueString($HTTP_POST_VARS['codice'], "text"));
mysql_select_db($database_db_clima, $db_clima);
$Result1 = mysql_query($insertSQL, $db_clima) or die(mysql_error());
$insertGoTo = "gestione_prodotti.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
//inizio upload
if ($_FILES['foto']<>""){
if (is_uploaded_file($_FILES['foto']['tmp_name'])) {
copy($_FILES['foto']['tmp_name'], "prodotti/".$_FILES['foto']['name']);
} else {
$continua=false;
}
}
//fine upload
header(sprintf("Location: %s", $insertGoTo));
}
?>
mentre il campo da inserire è:
<input name="foto" type="file" class="testoAzz" id="foto">
Ho fatto qualche casino?
Fabrizio

Rispondi quotando