Ciao a tutti,
stò modificando uno script che ho trovato,
funziona tutto a dovere meno che l'inserimentodel nome del file nel suo relativo campo nella tabella.
Funziona in questo modo,
la prima pagina mi fa selezionare l'immagine in locale e fa l'upload in una cartella, poi si va ad una seconda che fa il resoconto del file uplodato.
Da li ad una terza dove devo riempire un form con il resto dei dati.
Li trovo già il nome dell'immagine uplodata nel suo campo ma quando invio l'immagine e vado a vedere nel DB trovo 'NULL' il parametro di default.
Provo a postare il codice della prima e terza pagin sperando che qualcuno mi possa aiutare.
pag1
Codice PHP:
<?php require_once('FILE_CON_I_DATI.php'); ?>
<?php
session_start();
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "errore.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
$colname_livello = "1";
if (isset($_SESSION['MM_Username'])) {
$colname_livello = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_conncinema, $conncinema);
$query_livello = sprintf("SELECT * FROM accesso WHERE username = '%s'", $colname_livello);
$livello = mysql_query($query_livello, $conncinema) or die(mysql_error());
$row_livello = mysql_fetch_assoc($livello);
$totalRows_livello = mysql_num_rows($livello);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Tutti a tavola - Amministrazione</title>
</head>
<body>
<table width="100%" border="0">
<tr>
<td valign="top"><table width="100%" border="0" align="center">
<tr>
<td bgcolor="#666600" style="border:1px dashed #999999"><div align="center">
[b]
<font color="#FFFFCC" size="1"> Pannello
di controllo</font><font color="#FFFFCC" size="1">
</font>[/b]
</p>
</div></td>
</tr>
<tr>
<td bgcolor="#999966" style="border:1px dashed #999999"><div align="center">[b]Amministrazione[/b]</div></td>
</tr>
<tr>
<td bgcolor="#DAAF03" style="border:1px dashed #999999"><div align="center">
Username: <?php echo $_SESSION['MM_Username']; ?> </p>
[b]Inserimento nuova ricetta[/b]
[b]Step1 - Upload immagine
[/b][url="step2.php?foto=blank"][i]Clicca qui per saltare questo step. [/i][/url]
</p>
</p>
<FORM ENCTYPE="multipart/form-data" ACTION="upload.php" METHOD="post"><INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1024000">
<INPUT NAME="UploadedFile" TYPE="file">
<INPUT TYPE="submit" VALUE="Invia il file">
</FORM>
</p>
</div></td>
</tr>
</table></td>
</tr>
</table>
</p>
</body>
</html>
<?php
mysql_free_result($livello);
?>
pag3
Codice PHP:
<?php require_once('FILE_CON_I_DATI.php'); ?>
<?php
session_start();
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "errore.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
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_insert"])) && ($_POST["MM_insert"] == "inserimento")) {
$insertSQL = sprintf("INSERT INTO ricette (cucina, tipo, nome, tempo, difficolta, ingredienti, preparazione, note)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['cucina'], "text"),
GetSQLValueString($_POST['tipo'], "text"),
GetSQLValueString($_POST['nome'], "text"),
GetSQLValueString($_POST['tempo'], "text"),
GetSQLValueString($_POST['difficolta'], "text"),
GetSQLValueString($_POST['ingredienti'], "text"),
GetSQLValueString($_POST['preparazione'], "text"),
GetSQLValueString($_POST['note'], "text"));
mysql_select_db($database_conncinema, $conncinema);
$Result1 = mysql_query($insertSQL, $conncinema) or die(mysql_error());
$insertGoTo = "grazie.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$colname_livello = "1";
if (isset($_SESSION['MM_Username'])) {
$colname_livello = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_conncinema, $conncinema);
$query_livello = sprintf("SELECT * FROM accesso WHERE username = '%s'", $colname_livello);
$livello = mysql_query($query_livello, $conncinema) or die(mysql_error());
$row_livello = mysql_fetch_assoc($livello);
$totalRows_livello = mysql_num_rows($livello);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Tutti a tavola - Amministrazione</title>
</head>
<body>
<table width="100%" border="0">
<tr>
<td valign="top"><table width="100%" border="0" align="center">
<tr>
<td bgcolor="#666600" style="border:1px dashed #999999"><div align="center">
[b]
<font color="#FFFFCC" size="1"> Pannello
di controllo </span></font><font color="#FFFFCC" size="1">
</font>[/b]
</p>
</div></td>
</tr>
<tr>
<td bgcolor="#999966" style="border:1px dashed #999999"><div align="center">[b]Amministrazione[/b]</div></td>
</tr>
<tr>
<td bgcolor="#DAAF03" style="border:1px dashed #999999"><div align="center">
Username: <?php echo $_SESSION['MM_Username']; ?> </p>
[b]Inserimento nuova ricetta[/b]</p>
[b]Step2 - Dati necessari:[/b]</p>
<form action="<?php echo $editFormAction; ?>" method="POST" name="inserimento" id="inserimento">
Cucina:
<select name="cucina" id="cucina">
<option></option>
<option>Tradizionale</option>
<option>Etnica</option>
</select>
Tipologia:
<select name="tipo" id="tipo">
<option></option>
<option>Primi</option>
<option>Secondi</option>
</select>
Nome ricetta:
<input name="nome" type="text" id="nome" size=50 maxlength=50>
Tempo di preparazione:
<input name="tempo" type="text" id="tempo" size=50 maxlength=50>
Difficoltà:
<input name="difficolta" type="text" id="difficolta" size=50 maxlength=50>
Ingredienti:
<textarea name="ingredienti" cols=50 rows=10 id="ingredienti"></textarea>
Preparazione:
<textarea name="preparazione" cols=50 rows=10 id="preparazione"></textarea>
</p>
Foto:
<?php
$variabile= $_GET['foto'];
if ($variabile=="blank")
{
$variabile="";
}
else
{
}
?>
<input name="foto" type="text" id="foto" value="<?php echo($variabile); ?>"size="50">
</p>
Note:
<textarea name="note" cols=50 rows=10 id="note"></textarea>
</p>
<input name="inserisci" type="submit" id="inserisci" value="Inserisci">
<input name="cancella" type="reset" id="cancella" value="Cancella">
</p>
<input type="hidden" name="MM_insert" value="inserimento">
</form>
</div></td>
</tr>
</table></td>
</tr>
</table>
</p>
</body>
</html>
<?php
mysql_free_result($livello);
?>
Grazie in anticipo a tutti
P.S. Azzo quanto è lungo, spero non sia una mazzata per chi se lo trova davanti :-)