Ciao ragazzi, ho un problema che non riesco a risolvere.

Ho creato un mini-gestionale di esercizio col quale caricare del testo ed una foto.

Il problema è che, nonostante io non le abbia indicate, mi vengono mantenuti i valori nelle variabili $titolo e $corpo generate però solo in UPDATE quando recupero i dati da database.

Sicuramente sbaglio qualcosa di ovvio ma su stò script ormai mi sta andando insieme la vista.

Ho anche un problema di addslashes / stripslashes ma magari lo vediamo dopo.

N.B.
Sò che è un pò lunga ma è abbastanza ben organizzata e separato chiaramente nelle procedure.
Per ogni dubbio chiedetemi che vi indico dove guardare nel codice.

Grazie infinite

Di seguito il codice.
Codice PHP:
<?php

    
### CONNECT ###
    
require_once("connect_guestbook2.php");

    
    
### DELETE ###    
    
if(isset($_REQUEST["elimina"])){
    
        
$sql "select * from visite where id = '".$_REQUEST['id']."'";
        
$result mysql_query($sql);
        
$myrow mysql_fetch_array($result);        
            
        
$foto_grande "./img/guestbook/".$myrow["foto"];
        
$foto_piccola "./img/guestbook/p_".$myrow["foto"];
                
        if(
$myrow["foto"] != "" and file_exists($foto_grande)){        
            
unlink($foto_grande);        
        }
        
        if(
$myrow["foto"] != "" and file_exists($foto_piccola)){        
            
unlink($foto_piccola);        
        }
            
        
$sql "delete from visite where id = '".$_REQUEST['id']."'";
        
$result mysql_query($sql);            
                
    }
    
    
    
### UPDATE ###
    
if(isset($_REQUEST["modifica"])){
    
        
$sql "select * from visite where id = '".$_REQUEST['id']."'";
        
$result mysql_query($sql);
        if(
$myrow mysql_fetch_array($result)){
        
            
$titolo htmlentities(stripslashes($myrow["titolo"]));
            
$corpo htmlentities(stripslashes($myrow["corpo"]));
            
            if(isset(
$_REQUEST["update"])){        
                
                
$sql "update visite set titolo = '".addslashes(trim($_REQUEST["titolo"]))."', corpo = '".addslashes(trim($_REQUEST["corpo"]))."' where id = '".$_REQUEST['id']."'";    
                
mysql_query($sql);                              
                
                if(isset(
$_REQUEST["delete_foto"]) and !isset($_FILES["immagine"])){
                                
                   
$foto_grande "./img/guestbook/".$myrow["foto"];
                  
$foto_piccola "./img/guestbook/p_".$myrow["foto"];
                               
                   if(
$myrow["foto"] != "" and file_exists($foto_grande) and file_exists($foto_piccola)){                   
                      
unlink($foto_grande);
                      
unlink($foto_piccola);
                   }            
                    
                    
$sql "update visite set foto = '' where id = '".$myrow["id"]."' ";
                    
$result mysql_query($sql);
                                
                }
// delete_foto                
                
                
if(is_uploaded_file($_FILES["immagine"]["tmp_name"])){
                    
                   
$foto_grande "./img/guestbook/".$myrow["foto"];
                  
$foto_piccola "./img/guestbook/p_".$myrow["foto"];
                               
                   if(
$myrow["foto"] != "" and file_exists($foto_grande) and file_exists($foto_piccola)){                   
                      
unlink($foto_grande);
                      
unlink($foto_piccola);
                   }
                                               
                               
                   
$id $myrow["id"];
                   
$tmp_filename $_FILES["immagine"]["tmp_name"];
                   
$filename $id "_" $_FILES["immagine"]["name"];
                   
$path "./img/guestbook/";
                   
$pathfile $path $filename;
                   
                   if(
move_uploaded_file($tmp_filename,$pathfile)){
                   
                  
$size getimagesize($pathfile);
                  
$width $size[0];
                  
$height $size[1];
                  
                      
// funzione di resize
                  
if($width $height){
                  
                     
$new_width 100;
                     
$new_height ceil($height $new_width $width); 
                  
                  } elseif(
$width $height){
                  
                     
$new_height 100;
                     
$new_width ceil($width $new_height $height);    
                  
                  
                  }elseif(
$width $height){
                  
                     
$new_width 100;
                     
$new_height 100;
                  
                  }
                       
                       
$thumbnail_pathfile "./img/guestbook/p_";
                       
$thumbnail imageCreateTrueColor($new_width,$new_height) or die ("impossibile creare la miniatura");
                       
$original imageCreateFromJPEG($pathfile) or die("impossibile aprire l'originale");        
                       
imageCopyResampled($thumbnail,$original,0,0,0,0,$new_width,$new_height,$width,$height) or die("impossibile ridimensionare l'immagine");
                       
imageJpeg($thumbnail,$thumbnail_pathfile.$filename,80) or die("impossibile salvare la miniatura");
                       
imageDestroy($thumbnail);                    
                       
                       
$sql "update visite set foto = '".$filename."' where id = '".$id."'";
                       
$result mysql_query($sql);                                    
                                       
                   }
                        
                }    
                
            }                                            
        
        }                
    
    }
    
    
    
### INSERT ###
    
if(isset($_REQUEST["inserisci"])){        
            
        if(
$_REQUEST["titolo"] != "" and $_REQUEST["corpo"] != ""){
        
            
$sql "insert into visite(titolo,corpo) values('".addslashes(trim($_REQUEST["titolo"]))."','".addslashes(trim($_REQUEST["corpo"]))."')";
            
$result mysql_query($sql);
            if(
$result){
                
                
$id mysql_insert_id();
                
            }
            
            
            if(
is_uploaded_file($_FILES["immagine"]["tmp_name"])){
            
                
$tmp_filename $_FILES["immagine"]["tmp_name"];
                
$filename $id "_" $_FILES["immagine"]["name"];
                
$path "./img/guestbook/";
                
$pathfile $path $filename;
                
                if(
move_uploaded_file($tmp_filename,$pathfile)){
                
            
$size getimagesize($pathfile);
            
$width $size[0];
            
$height $size[1];
            
                
// funzione di resize
            
if($width $height){
            
               
$new_width 100;
               
$new_height ceil($height $new_width $width); 
            
            } elseif(
$width $height){
            
               
$new_height 100;
               
$new_width ceil($width $new_height $height);    
            
            
            }elseif(
$width $height){
            
               
$new_width 100;
               
$new_height 100;
            
            }
                    
                    
$thumbnail_pathfile "./img/guestbook/p_";
                    
$thumbnail imageCreateTrueColor($new_width,$new_height) or die ("impossibile creare la miniatura");
                    
$original imageCreateFromJPEG($pathfile) or die("impossibile aprire l'originale");        
                    
imageCopyResampled($thumbnail,$original,0,0,0,0,$new_width,$new_height,$width,$height) or die("impossibile ridimensionare l'immagine");
                    
imageJpeg($thumbnail,$thumbnail_pathfile.$filename,80) or die("impossibile salvare la miniatura");
                    
imageDestroy($thumbnail);                    
                    
                    
$sql "update visite set foto = '".$filename."' where id = '".$id."'";
                    
$result mysql_query($sql);                                    
                                    
                }
                        
            }            
                        
        
        }        
        
    }
    
    
    
?>


<!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 name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="imagetoolbar" content="no" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="revisit-after" content="7 days" />
<meta http-equiv="robots" content="index,follow" />
<meta http-equiv="Cache-Control" content="cache, must-revalidate" />
<meta http-equiv="pragma" content="cache" />
<script language="JavaScript" type="text/javascript" src="js/global.js"></script>

<link rel="stylesheet" type="text/css" href="css/stile.css" />
<title>Guestbook2</title>
</head>
<body>


    <form action="<?php echo $_SERVER['PHP_SELF'?>" method="post" enctype="multipart/form-data">
        <?php
        
if($_GET["modifica"]){
        
?>
        <input type="hidden" name="modifica" value="1" />
        <input type="hidden" name="id" value="<?php echo $myrow['id']; ?>" />
        <?php
        
}
        
?>
        <div class="campo">
            <label>Titolo</label>
            <input type="text" class="text" name="titolo" value="<?php echo $titolo?>" />
        </div>
        
        <div class="campo">
            <label>Corpo</label>
            <textarea name="corpo"><?php echo $corpo?></textarea>
        </div>
        
        <div><input type="file" class="text" name="immagine" /></div>
        

        
        <?php
        
if(isset($_REQUEST["modifica"])){
        
?>
            <?php
            
if($myrow["foto"] != ""){
            
?>
            <div><input type="checkbox" name="delete_foto" value="1" style="vertical-align:middle;" /> cancella la foto</div>
            <?php
            
}
            
?>                    
        <div><input type="submit" name="update" value="modifica" /></div>
        <?php
        
}else {
        
?>
        <div><input type="submit" name="inserisci" value="inserisci" /></div>
        <?php
        
}
        
?>
    
    </form>

    
    <?php
    $sql 
"select * from visite";
    
$result mysql_query($sql);
    if(
$myrow mysql_fetch_array($result)){
    
?>
    
        <table class="editor">
            <tr>
                <th width="60">Azioni</th>
                <th width="200">Titolo</th>
                <th width="400">Corpo</th>
                <th width="60">Foto</th>
            </tr>
        <?php
        $n 
1;
        do {
        
        if(
$n == 0){        
            
$riga "pari";        
        } else {
            
$riga "dispari";
        }
        
                
        
?>
            <tr class="<?php echo $riga?>">
                <td class="middle">
                    
                    [url="<?php echo $_SERVER['PHP_SELF'?>?modifica=1&id=<?php echo $myrow['id'];?>"][img]img/modifica.gif[/img][/url]
                    [url="<?php echo $_SERVER['PHP_SELF'?>?elimina=1&id=<?php echo $myrow['id'];?>"][img]img/elimina.gif[/img][/url]
                
                </td>
                <td class="top"><?php echo htmlentities(stripslashes(substr($myrow['titolo'],0,100))); ?></td>
                <td class="top"><?php echo htmlentities(stripslashes(nl2br(substr($myrow['corpo'],0,300)))); ?></td>
                <td class="middle">
                    <?php
                    
if($myrow['foto'] != ''){
                    
                        if(
file_exists("./img/guestbook/".$myrow['foto'])){
                        
                            
$size getImageSize("./img/guestbook/".$myrow['foto']);
                            
$width $size[0];
                            
$height $size[1];                                                        
                        
                        }
                    
                    
?>
                        [url="javascript:popup('popup.php?id=<?php echo $myrow['id']; ?>','','<?php echo $width ?>','<?php echo $height ?>','')"][img]./img/guestbook/p_<?php echo $myrow['foto']; ?>[/img][/url]
                    <?php
                    
}
                    
?>
                </td>            
            </tr>        
        <?php        
        $n
++;
        } while(
$myrow mysql_fetch_array($result));
        
?>
        
        </table>
        
    <?php
    
}            
    
?>
    


</body>
</html>