Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    346

    upload in cartella dell'ultimo id inserito nel db

    ciao,
    in questa funzione, l'id del file che vado ad inserire nel db deve corrisponde anche al "nome" (numerico) dell'immagine che viene salvata nelle due cartelle (img & imgx),
    il problema è che ogni volta che inserisco una nuova immagine, invece di rinominarla con l'id che prende (incrementale), viene sovcrascritta sempre con lo stesso id 0(zero)

    Come devo impostare la variabile
    Codice PHP:
    $newname="$dbid.jpg"
    affinchè prenda il nome dell'id che inserisco nel db?

    Codice PHP:

    //inserimento nel db
    $sqltxt="INSERT INTO amb00 (id,txt01,txt02) VALUES ($wid0,'$wtxt01','$wtxt02');";
    $result $db->Execute($sqltxt) or die("Errore nella QUERY: $sqltxt. " $db->ErrorMsg());

    $wid0 intval($wid0);  // anti inoculation con valori numerici

    $sqltxt="select * from amb00 where id=$wid0";
    $result $db->Execute($sqltxt) or die("Errore nella QUERY: $sqltxt. " $db->ErrorMsg());

    $dbid=$result->fields("id");

                   
    //-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-//
    if ($wfile!="") {
        
    $newname="$dbid.jpg";
        
    //echo "$newname";
        
    $filegrosso="../".$ambpathtoweb.$ambpathtoweb_big."/".$newname;   // directory immagini codificate
    //   echo"DEBUG-file-->$wfile 
    \n";
    //   echo"
    DEBUG-filegrosso-->$filegrosso 
    \n";
        copy(
    $wfile,$filegrosso);
                   //-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-//
                   //-------> creo immagine ridotta x icona <-------//
                   //-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-//

        
    $cur_dir="../".$ambpathtoweb.$ambpathtoweb_big;
        
    $cur_file=$newname;
        
    $w=200;
        
    $h=150;    
        
    $filepiccolo="../".$ambpathtoweb.$ambpathtoweb_small; // ."/".$newname;   // directory immagini codificate

    //    echo"
    DEBUG-curdir-->$cur_dir 
    \n";
    //    echo"
    DEBUG-curfile-->$cur_file 
    \n";
    //    echo"
    DEBUG-filepiccolo-->$filepiccolo 
    \n";

           resize(
    $cur_dir$cur_file$w,$h$filepiccolo);
    }
                   //-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-//

    ges_amb60(
    $wid0);


  2. #2
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    346
    forse ho trovato una soluzione, ma ho bisogno di sapere come posso richiamare l'ultimo record inserito... in modo da riprendere l'id(chiave primaria) con il quale andrò poi a chiamare l'immagine

    per cercare di rendere il codice il + leggibile possibile lo inserisco per intero!! pls...help me almeno per una volta
    Codice PHP:

    //==========================================================================
    //==========================================================================
    //========================   GESTIONE AMBIENTI      ========================
    //==========================================================================
    //==========================================================================

    function ges_amb60() {

    include (
    "../config.inc");
    include (
    "../adodbconnect.inc");

    $sqltxt="select * from amb00";
    $result $db->Execute($sqltxt) or die("Errore nella QUERY: $sqltxt. " $db->ErrorMsg());


    echo    
    "<table width=\"60%\" border=\"1\">\n";
    echo    
    "<tr>"
           
    // titolo sezione
           
    ."<td width=\"40%\" valign=\"middle\" align=\"center\">Gestione Ambienti</td>" 
           
    // aggiungi ambiente
           
    ."<td width=\"10%\" valign=\"middle\" align=\"center\"><a href=\"admin.php?op=64\">Aggiungi Ambiente</a></td>"  
           
    // torna indietro
           
    ."<td width=\"10%\" valign=\"middle\" align=\"center\"><a href=\"admin.php?op=\">Amministrazione</a></td>"
           
    ."</tr>";
    echo    
    "</table>\n";

    echo    
    "<table width=\"70%\" border=\"1\">\n";

            while (!
    $result->EOF)       // inizio ciclo do while per MENU
            
    {

            
    $dbid0=$result->fields("id");
            
    $dbtxt1=$result->fields("txt01");
            
    $dbtxt2=$result->fields("txt02");
            
            
    $fileimmagine="../$ambpathtoweb$ambpathtoweb_small/$dbid0.jpg";
            
            echo 
    "<tr>"
    // Decommentare per avere in elenco l'id della categoria
    //             ."<td width=\"10%\">$dbid0</td>"
                  
    ."<td width=\"20%\"><img src=\"$fileimmagine\" alt=\"\" title=\".1\" width=\"200\" height=\"150\" border=\"0\" /></td>"
                 
    ."<td width=\"30%\">$dbtxt1</td>"
                 
    ."<td width=\"30%\">$dbtxt2</td>"
                 
    ."<td width=\"10%\"><a href=\"admin.php?op=66&amp;wid0=$dbid0\">Modifica</a></td>"
                 
    ."<td width=\"10%\"><a href=\"admin.php?op=68&amp;wid0=$dbid0\" onclick=\"javascript:return confirmAction()\">Cancella</a></td>"
                 
    ."</tr>";

            
    $result->MoveNext();

            }

    echo    
    "</table>\n";

    }


    //==============================================================================
    //=============   INSERIMENTO AMBIENTE  ===========================
    //===================================================================

    function ges_amb64($wid0) {

    include (
    "../config.inc");
    include (
    "../adodbconnect.inc");

    echo 
    "<table width=\"50%\" border=\"1\" align=\"center\">\n"
    ."<tr>"
    ."<td width=\"25%\" align=\"center\">Gestione Ambiente</td>"
    ."</tr>"
    ."<td width=\"10%\" valign=\"middle\" align=\"center\"><a href=\"admin.php?op=60\">Exit</a></td>"
    ."</table>\n";
    echo    
    "</table>\n";

    echo    
    "<table width=\"20%\" border=\"1\">\n";
            
            
    echo    
    "</table>\n";


    //------------------> FORM ambiente <------------------

    //echo    "</table>\n";
    echo"<form action=\"admin.php?op=65\" name=\"new_amb\" method=\"post\" enctype=\"multipart/form-data\">\n"
                 
    ."<table width=\"90%\" border=\"1\">\n"
                 
    ."<tr>"
                 
    ."<td width=\"20%\"></td>"
                 
    ."<td width=\"70%\"><input type=\"submit\" name=\"store\" value=\"Memorizza\" /><input type=\"reset\" name=\"reimposta\" /></td>"
                 
    ."</tr>"
                 
    //scelgo immagine
                 
    ."<tr>"
                 
    ."<td width=\"20%\">Associa Immagine:</td>"
                 
    ."<td width=\"70%\"><input type=\"file\" size=\"100\" name=\"dbid0\" /></td>"
                 
    ."</tr>"
                 
    ."<tr>"
                 
    ."<td width=\"20%\">Text 1</td>"
                 
    ."<td width=\"70%\"><textarea name=\"wtxt01\" rows=\"4\" cols=\"90\"></textarea></td>"
                 
    ."</tr>"
                 
    ."<tr>"
                 
    ."<td width=\"20%\">Text 2</td>"
                 
    ."<td width=\"70%\"><textarea name=\"wtxt02\" rows=\"4\" cols=\"90\"></textarea></td>"
                 
    ."</tr>"
                   
    ."</table>\n"
                 
    ."<input type=\"hidden\" name=\"wid0\" value=\"$dbid0\" />"
                 

    ."</form>\n";

    }


    //----------------------------------------------------------------------------
    //------------ INSERIMENTO AMBIENTE IN DB ------------------------------------
    //----------------------------------------------------------------------------

    function ges_amb65($wid0,$wtxt01,$wtxt02,$wfile) {

    include (
    "../config.inc");
    include (
    "../adodbconnect.inc");

    $wid0 intval($wid0);  // anti inoculation con valori numerici

    //inserimento nel db
    $sqltxt="INSERT INTO amb00 (id,txt01,txt02) VALUES ($wid0,'$wtxt01','$wtxt02');";
    $result $db->Execute($sqltxt) or die("Errore nella QUERY: $sqltxt. " $db->ErrorMsg());

    $wid0 intval($wid0);  // anti inoculation con valori numerici

    $sqltxt="select * from amb00 where id=$wid0";
    $result $db->Execute($sqltxt) or die("Errore nella QUERY: $sqltxt. " $db->ErrorMsg());

    $dbid0=$result->fields("id");

                   
    //-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-//
    if ($wfile!="") {
        
    $newname="$dbid0.jpg";
        
    //echo "$newname";
        
    $filegrosso="../".$ambpathtoweb.$ambpathtoweb_big."/".$newname;   // directory immagini codificate
    //   echo"DEBUG-file-->$wfile 
    \n";
    //   echo"
    DEBUG-filegrosso-->$filegrosso 
    \n";
        copy(
    $wfile,$filegrosso);
                   //-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-//
                   //---------> creo immagine ridotta x icona <---//
                   //-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-//

        
    $cur_dir="../".$ambpathtoweb.$ambpathtoweb_big;
        
    $cur_file=$newname;
        
    $w=200;
        
    $h=150;    
        
    $filepiccolo="../".$ambpathtoweb.$ambpathtoweb_small; // ."/".$newname;   // directory immagini codificate

    //    echo"
    DEBUG-curdir-->$cur_dir 
    \n";
    //    echo"
    DEBUG-curfile-->$cur_file 
    \n";
    //    echo"
    DEBUG-filepiccolo-->$filepiccolo 
    \n";

           resize(
    $cur_dir$cur_file$w,$h$filepiccolo);
    }
                   //-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-//

    ges_amb60(
    $wid0);
    }

    //==============================================================
    //=============   MODIFICA AMBIENTE  ===========================
    //==============================================================


    function ges_amb66(
    $wid0) {

    include ("
    ../config.inc");
    include ("
    ../adodbconnect.inc");

    echo "
    <table width=\"50%\" border=\"1\" align=\"center\">\n"
    ."<tr>"
    ."<td width=\"25%\" align=\"center\">Gestione Modifica Ambiente</td>"
    ."<td width=\"10%\" valign=\"middle\" align=\"center\"><a href=\"admin.php?op=60\">Amministrazione</a></td>"
    ."</tr>"
    ."</table>\n";
    echo    
    "</table>\n";

    echo    
    "<table width=\"20%\" border=\"1\">\n";
            
           
    echo    
    "</table>\n";

    //------------------> FORM articolo <------------------

    $wid0 intval($wid0);  // anti inoculation con valori numerici
    $sqltxt="select * from amb00 where id=$wid0 "//cat0=$wid0 and cat1=$wid1 and cat2=$wid2";
    $result $db->Execute($sqltxt) or die("Errore nella QUERY: $sqltxt. " $db->ErrorMsg());
    if (
    $result->EOF) {
      }
    else
      {          
    // trovato

            
    $dbid0=$result->fields("id");
            
    $dbtxt1=$result->fields("txt01");
            
    $dbtxt2=$result->fields("txt02");



    //------------------> FORM articolo <------------------

    //<input type="button" value="Reload Page" onClick="window.location.reload()">



    echo"<form action=\"admin.php?op=67\" name=\"new_amb\" method=\"post\" enctype=\"multipart/form-data\">\n"
                 
    ."<table width=\"90%\" border=\"1\">\n"

                 
    ."<tr>"
                 
    ."<td width=\"20%\"></td>"
    //             ."<td width=\"70%\"><input type=\"submit\" name=\"store\" value=\"Memorizza\" /><input type=\"reset\" name=\"reimposta\" /></td>"
                 
    ."<td width=\"70%\"><input type=\"submit\" name=\"store\" value=\"Memorizza\" /><input type=\"reset\" name=\"reimposta\" /></td>"
                 
    ."</tr>"

                 
    //scelgo immagine
                 
    ."<tr>"
                 
    ."<td width=\"20%\">Riassocia Immagine:</td>"
                 
    ."<td width=\"70%\"><input type=\"file\" size=\"100\" name=\"wfile\" /></td>"
                 
    ."</tr>"
                 
    ."<tr>"
                 
    ."<td width=\"20%\">Text 1</td>"
                 
    ."<td width=\"70%\"><textarea name=\"wtxt01\" rows=\"4\" cols=\"90\">$dbtxt1</textarea></td>"
                 
    ."</tr>"
                 
    ."<tr>"
                 
    ."<td width=\"20%\">Text 2</td>"
                 
    ."<td width=\"70%\"><textarea name=\"wtxt02\" rows=\"4\" cols=\"90\">$dbtxt2</textarea></td>"
                 
    ."</tr>"
                 
    ."</table>\n"
                 
    ."<input type=\"hidden\" name=\"wid0\" value=\"$dbid0\" />"
                 
    ."</form>\n";
    //echo "-->$dbid<---";
        
    }
    }
    //==============================================================================

    function ges_amb67($wid0,$wtxt01,$wtxt02,$wfile) {

    include (
    "../config.inc");
    include (
    "../adodbconnect.inc");

                   
    if (
    $wfile!="") {
        
    $newname="$dbid0.jpg";
        
    $filegrosso="../".$imagepathtoweb.$imagepathtoweb_big."/".$newname;   // directory immagini codificate

        
    copy($wfile,$filegrosso);
                   
    //-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-//
                   //---------> creo immagine ridotta x icona <---//
                   //-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-//

        
    $cur_dir="../".$imagepathtoweb.$imagepathtoweb_big;
        
    $cur_file=$newname;
        
    $w=200;
        
    $h=150;    
        
    $filepiccolo="../".$imagepathtoweb.$imagepathtoweb_small// ."/".$newname;   // directory immagini codificate


           
    resize($cur_dir$cur_file$w,$h$filepiccolo);
    }
                  
    $sqltxt="UPDATE amb00 SET txt01='$wtxt01',txt02='$wtxt02' where id=$dbid0";
    $result $db->Execute($sqltxt) or die("Errore nella QUERY: $sqltxt. " $db->ErrorMsg());


    ges_amb60();
    }

    //==============================================================================
    //==============================================================================

    function ges_amb68($wid0) {

    include (
    "../config.inc");
    include (
    "../adodbconnect.inc");

    $sqltxt="DELETE FROM amb00 where id=$wid0";
    //echo"DEBUG-->$sqltxt 
    \n";

    $result = $db->Execute($sqltxt) or die("Errore nella QUERY$sqltxt" . $db->ErrorMsg());

    $filename=$wid0;

    unlink ("
    ../imgnuovo/img/".$filename.".jpg");
    unlink ("
    ../imgnuovo/imgx/".$filename.".jpg");
     

    ges_amb60();

    }
    //============================================================================== 
    il problema principale è nell'inserimento dell'immagine.
    nel db vengono inseriti correttamente tutti e 3 i campi (id=nome dell'immagine che viene salvata poi nelle due cartelle, txt01, txt02)

    e successivamente mi da un errore nella parte in cui vado a modificare il testo o l'immagine. quando vado nella sezione memorizza mi da questo errore:

    Errore nella QUERY: UPDATE amb00 SET txt01='fhjfg',txt02='jgj' where id=. You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

    riuscite a capirci quaalcosa?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.