Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    dati id errati dal db nella pagina php

    Piccolo problema che non capisco!!!

    ho creato delle pagine tra cui una che mi elimina delle immagini nelle cartelle e il percorso dal database solo che nel momento in cui carico la pagina per vedere i dati mi tira fuori gli indici non aggiornati in ordine tipo passa dal 25 al 27 se ho eliminato ad esempio la 26 ma la pagina che visualizza i dati mi tira fuori una riga che non esiste che corrisponde all'indice 26 (eliminato) come correggo questo problema? posto il codice sia dell'insert che della tabella

    upload.php
    Codice PHP:
            include("config.php");

            include(
    'connessione.php');

            
    //if the for has submittedd
            
    if (isset($_POST['upForm'])){

           
    $file_type $_FILES['imgfile']['type'];
           
    $file_name $_FILES['imgfile']['name'];
           
    $file_size $_FILES['imgfile']['size'];
           
    $file_tmp $_FILES['imgfile']['tmp_name'];
           
    $descrizione $_POST['descrizione'];

           
    //check if you have selected a file.
           
    if(!is_uploaded_file($file_tmp)){
              
           
    header("Location: upload_immagini.php"); /* Redirect browser */
              

              
    exit(); //exit the script and don't do anything else.
           
    }
           
    //check file extension
           
    $ext strrchr($file_name,'.');
           
    $ext strtolower($ext);
           if ((
    $extlimit == "yes") && (!in_array($ext,$limitedext))) {
              echo 
    "Wrong file extension.  
    --<a href=\"
    $_SERVER[PHP_SELF]\">back</a>";
              exit();
           }
           
    //get the file extension.
           
    $getExt explode ('.'$file_name);
           
    $file_ext $getExt[count($getExt)-1];

           
    //create a random file name
           
    $rand_name md5(time());
           
    $rand_namerand(0,999999999);
           
    //get the new width variable.
           
    $ThumbWidth $img_thumb_width;

           
    //keep image type
           
    if($file_size){
              if(
    $file_type == "image/pjpeg" || $file_type == "image/jpeg"){
                   
    $new_img imagecreatefromjpeg($file_tmp);
               }elseif(
    $file_type == "image/x-png" || $file_type == "image/png"){
                   
    $new_img imagecreatefrompng($file_tmp);
               }elseif(
    $file_type == "image/gif"){
                   
    $new_img imagecreatefromgif($file_tmp);
               }
               
    //list width and height and keep height ratio.
               
    list($width$height) = getimagesize($file_tmp);
               
    $imgratio=$width/$height;
               if (
    $imgratio>1){
                  
    $newwidth $ThumbWidth;
                  
    $newheight $ThumbWidth/$imgratio;
               }else{
                     
    $newheight $ThumbWidth;
                     
    $newwidth $ThumbWidth*$imgratio;
               }
               
    //function for resize image.
               
    if (function_exists(imagecreatetruecolor)){
               
    $resized_img imagecreatetruecolor($newwidth,$newheight);
               }else{
                     die(
    "Error: Please make sure you have GD library ver 2+");
               }
               
    imagecopyresized($resized_img$new_img0000$newwidth$newheight$width$height);
               
    //save image
               
    ImageJpeg ($resized_img,"$path_thumbs/$rand_name.$file_ext");
               
    ImageDestroy ($resized_img);
               
    ImageDestroy ($new_img);
               
    //print message
               //echo "
    Image Thumb: <a href=\"$path_thumbs/$rand_name.$file_ext\">$path_thumbs/$rand_name.$file_ext</a>";
            }

            
    //upload the big image
            
    move_uploaded_file ($file_tmp"$path_big/$rand_name.$file_ext");

            
    //echo "
    Image Big: <a href=\"$path_big/$rand_name.$file_ext\">$path_big/$rand_name.$file_ext</a>";

            
    //echo "

    --<a href=\"$_SERVER[PHP_SELF]\">back</a>";

            
    //echo "$rand_name.$file_ext";

            
    $query "INSERT INTO `fotoband` (`id`,`big`,`thumbs`, `descrizione`, `rand_name`) VALUES ('', '$path_big/$rand_name.$file_ext', '$path_thumbs/$rand_name.$file_ext', '$descrizione', '$rand_name')";

            
    /* //test for insert db ok
            echo "$path_big/$rand_name.$file_ext";
            echo "
    ";
            echo "$path_thumbs/$rand_name.$file_ext";
            echo "
    ";
            echo "$descrizione";
            echo "
    ";

            */

            
    $result mysql_query($query) or die("Query failed: ".mysql_error());

            if(
    $result) {
              echo 
    "<div class='err'>

    L'immagine è stata inserita correttamente


    </div>"
    ;
                  echo 
    "<meta http-equiv=refresh content=2;url=upload_immagini.php>";
              } else {
                     echo 
    "<div class='err'>
    Errore inserimento immagine.</div>"
    ;
                     }


          }else{ 
    //if the form hasn't been submitted.

          //print the form
          
    echo "

          <div id='margini02'>
          <form method=\"post\" name=\"upForm\" enctype=\"multipart/form-data\" action=\"
    $_SERVER[PHP_SELF]\">
          <table width='450' cellspacing='0' cellpadding='0' border='0' align='center' bgcolor='#ffffff'>
          <tr>
              <td colspan='3' height='40'></td>
          </tr>
          <tr>
              <td colspan='3'><div class='h3'>:: Inserisci le immagini singolarmente tramite Upload:</div></td>
          </tr>
          </table>
          


          <div id='bordo_contorni2'>
          <table width='450' cellspacing='0' cellpadding='0' border='0' align='center'>
          <tr>
              <td colspan='3' height='30'></td>
          </tr>
          <tr>
              <td class='h5'>Immagine:</td>
            <td width='30'></td>
              <td><input type='file' name='imgfile' class='inputbox'></td>
          </tr>
          <tr>
              <td colspan='3' height='10'></td>
          </tr>
          <tr>
              <td class='h5'>Descrizione:</td>
            <td width='30'></td>
              <td><input class='inputbox' type=\"text\" name=\"descrizione\" maxlength=\"150\" /></td>
          </tr>
          <tr>
              <td colspan='3' height='10'></td>
          </tr>
          <tr>
              <td></td>
            <td width='30'></td>
              <td><input type=\"Submit\" name=\"upForm\" value=\"Upload\" class='submit'></td>
          </tr>
          <tr>
              <td colspan='3' height='30'></td>
          </tr>
          </table>
          </div>
          </form>
          </div>"
    ;

    }

    ?> 
    tabella
    Codice PHP:
    CREATE TABLE `fotoband` (
      `
    idint(11NOT NULL auto_increment,
      `
    bigvarchar(100) default NULL,
      `
    thumbsvarchar(100NOT NULL,
      `
    rand_namevarchar(20NOT NULL,
      `
    descrizionemediumtext NOT NULL,
      
    PRIMARY KEY  (`id`)
    ENGINE=MyISAM AUTO_INCREMENT=96 DEFAULT CHARSET=latin1 AUTO_INCREMENT=96 

  2. #2
    non capisco... ho ricreato la tabella per non toccare l'id del db e ho utilizzato idband come campo aggiornando tutte le altre pagine compresa quella che fa il delete ma ora elimina i campi in progressione cioè quando elimino un immagine nel db non elimina il corripondente ma un altra...

    posto il db e la pagine delete.php

    Codice PHP:
    CREATE TABLE band (
      
    idband INT(11NOT NULL AUTO_INCREMENT,
      
    big VARCHAR(45NULL,
      
    thumbs VARCHAR(45NULL,
      
    rand_name VARCHAR(45NULL,
      
    PRIMARY KEY(idband)
    ); 
    Codice PHP:
    <?

    include('connessione.php');

    $selezione "SELECT * FROM band";
    $result mysql_query($selezione);
    $riga mysql_fetch_array($result);

    $thumbs $riga['thumbs'];
    $big $riga['big'];

    $id$riga['idband'];


    echo 
    "$thumbs";


    if(
    file_exists($thumbs)){

                                if(
    $thumbs != '') {
                                
    unlink($thumbs);
                                }
                                if(
    $big != '') {
                                
    unlink($big);
                                }

                                
    $query="DELETE FROM band WHERE idband='$id'";
                                
    $result mysql_query($query) or die("Query failed: " mysql_error());

                                echo 
    "<div class='h11'>

    Eliminazione avvenuta con successo!</div>"
    ;
                                }else{
                                echo
    "file non esistente";
                                }
                            
                            

                            
    //echo "<meta http-equiv=refresh content=3;url=artview_el.php>";

                    
    ?>

  3. #3
    nessuno riesce a suggerirmi dove possa essere il problema?

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 © 2025 vBulletin Solutions, Inc. All rights reserved.