Salve a tutti,
questo script mi inserisce correttamente il record ma inserisce nei campi immagine il $NomefileOrig invece di $nuovo_nome col percorso e non effettua l'upload dei file...non riesco a capire dove sbaglio::::tks in advance !
(sotto lo script intero, se servisse a qualcuno)
#####################
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
######Gestione Img###
$NomefileOrig1 = $_FILES['Logo']['name'];
$NomefileOrig2 = $_FILES['Foto']['name'];
//valore di record_id passato da form usato poi per ri-nominare il file
$file_temp0=($_FILES['Logo']['tmp_name']);
$file_temp1=($_FILES['Foto']['tmp_name']);
//file temporaneo che contiene l'immagine caricata
$percorso="foto/";
//cartella sul server dove verrà spostata la foto
$nuovo_nome0=$percorso.$NomefileOrig1;
$nuovo_nome1=$percorso.$NomefileOrig2;
##############
$insertSQL = sprintf("INSERT INTO marcalinea (ID_MarcaLinea, Marca_, LineaProdotto_, Logo, Foto, Descrizione, Pdf_) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['ID_MarcaLinea'], "int"),
GetSQLValueString($_POST['Marca_'], "int"),
GetSQLValueString($_POST['LineaProdotto_'], "int"),
GetSQLValueString($_POST['Logo'], "text"),
GetSQLValueString($_POST['Foto'], "text"),
GetSQLValueString($_POST['Descrizione'], "text"),
GetSQLValueString($_POST['Pdf_'], "int"));
mysql_select_db($database_Conn_Bianchi, $Conn_Bianchi);
$Result1 = mysql_query($insertSQL, $Conn_Bianchi) or die(mysql_error());
######### carica immagini ########
move_uploaded_file($file_temp0, $nuovo_nome0);
move_uploaded_file($file_temp1, $nuovo_nome1);
###############################
$insertGoTo = "view.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
##########################################
###script intero inserimento record + upl img############
<?php require_once('Connections/Conn_Bianchi.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")) {
######Gestione Img###
$NomefileOrig1 = $_FILES['Logo']['name'];
$NomefileOrig2 = $_FILES['Foto']['name'];
//valore di record_id passato da form usato poi per ri-nominare il file
$file_temp0=($_FILES['Logo']['tmp_name']);
$file_temp1=($_FILES['Foto']['tmp_name']);
//file temporaneo che contiene l'immagine caricata
$percorso="foto/";
//cartella sul server dove verrà spostata la foto
$nuovo_nome0=$percorso.$NomefileOrig1;
$nuovo_nome1=$percorso.$NomefileOrig2;
##############
$insertSQL = sprintf("INSERT INTO marcalinea (ID_MarcaLinea, Marca_, LineaProdotto_, Logo, Foto, Descrizione, Pdf_) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['ID_MarcaLinea'], "int"),
GetSQLValueString($_POST['Marca_'], "int"),
GetSQLValueString($_POST['LineaProdotto_'], "int"),
GetSQLValueString($_POST['Logo'], "text"),
GetSQLValueString($_POST['Foto'], "text"),
GetSQLValueString($_POST['Descrizione'], "text"),
GetSQLValueString($_POST['Pdf_'], "int"));
mysql_select_db($database_Conn_Bianchi, $Conn_Bianchi);
$Result1 = mysql_query($insertSQL, $Conn_Bianchi) or die(mysql_error());
######### carica immagini ########
move_uploaded_file($file_temp0, $nuovo_nome0);
move_uploaded_file($file_temp1, $nuovo_nome1);
###############################
$insertGoTo = "view.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_Conn_Bianchi, $Conn_Bianchi);
$query_QryGeneral = "SELECT * FROM lineeprodotto, marcalinea, marche WHERE marcalinea.Marca_ = marche.ID_Marche AND marcalinea.LineaProdotto_ = lineeprodotto.ID_Linee";
$QryGeneral = mysql_query($query_QryGeneral, $Conn_Bianchi) or die(mysql_error());
$row_QryGeneral = mysql_fetch_assoc($QryGeneral);
$totalRows_QryGeneral = mysql_num_rows($QryGeneral);
mysql_select_db($database_Conn_Bianchi, $Conn_Bianchi);
$query_QryMarche = "SELECT * FROM marche";
$QryMarche = mysql_query($query_QryMarche, $Conn_Bianchi) or die(mysql_error());
$row_QryMarche = mysql_fetch_assoc($QryMarche);
$totalRows_QryMarche = mysql_num_rows($QryMarche);
mysql_select_db($database_Conn_Bianchi, $Conn_Bianchi);
$query_QryLineaProdotto = "SELECT * FROM lineeprodotto";
$QryLineaProdotto = mysql_query($query_QryLineaProdotto, $Conn_Bianchi) or die(mysql_error());
$row_QryLineaProdotto = mysql_fetch_assoc($QryLineaProdotto);
$totalRows_QryLineaProdotto = mysql_num_rows($QryLineaProdotto);
mysql_select_db($database_Conn_Bianchi, $Conn_Bianchi);
$query_QryMarcaLinea = "SELECT * FROM marcalinea";
$QryMarcaLinea = mysql_query($query_QryMarcaLinea, $Conn_Bianchi) or die(mysql_error());
$row_QryMarcaLinea = mysql_fetch_assoc($QryMarcaLinea);
$totalRows_QryMarcaLinea = mysql_num_rows($QryMarcaLinea);
?><!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>Documento senza titolo</title>
</head>
<body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">ID_MarcaLinea:</td>
<td><input type="text" name="ID_MarcaLinea" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Marca_:</td>
<td><select name="Marca_">
<?php
do {
?>
<option value="<?php echo $row_QryMarche['ID_Marche']?>"><?php echo $row_QryMarche['Marca']?></option>
<?php
} while ($row_QryMarche = mysql_fetch_assoc($QryMarche));
$rows = mysql_num_rows($QryMarche);
if($rows > 0) {
mysql_data_seek($QryMarche, 0);
$row_QryMarche = mysql_fetch_assoc($QryMarche);
}
?>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">LineaProdotto_:</td>
<td><select name="LineaProdotto_">
<?php
do {
?>
<option value="<?php echo $row_QryLineaProdotto['ID_Linee']?>"><?php echo $row_QryLineaProdotto['LineaProdotto']?></option>
<?php
} while ($row_QryLineaProdotto = mysql_fetch_assoc($QryLineaProdotto));
$rows = mysql_num_rows($QryLineaProdotto);
if($rows > 0) {
mysql_data_seek($QryLineaProdotto, 0);
$row_QryLineaProdotto = mysql_fetch_assoc($QryLineaProdotto);
}
?>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Logo
:</td>
<td><input name="Logo" type="file" id="Logo" /></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Foto
:</td>
<td><input name="Foto" type="file" id="Foto" /></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Descrizione:</td>
<td><input type="text" name="Descrizione" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Pdf_:</td>
<td><input type="text" name="Pdf_" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"></td>
<td><input type="submit" value="Inserisci record">
<input type="hidden" name="MM_insert" value="form1" /></td>
</tr>
</table>
</form>
</body>
</html>
<?php
mysql_free_result($QryGeneral);
mysql_free_result($QryMarche);
mysql_free_result($QryLineaProdotto);
mysql_free_result($QryMarcaLinea);
?>