Visualizzazione dei risultati da 1 a 10 su 11

Visualizzazione discussione

  1. #2
    Utente di HTML.it
    Registrato dal
    Jan 2011
    Messaggi
    360
    Aggiornamento:


    Ho recuperato e modificato il seguente codice:

    Codice PHP:
    <?php

    error_reporting
    (E_ALL);
    ini_set('display_errors'true);

    $db = new PDO('mysql:dbname=prodotti;host=localhost''root''root');


    if (isset(
    $_POST['formsubmitted'])) { //if form was submitted

        
    $error_array = array();//Declare An Array to store any error message

        // check all images for upload errors
        // you should probably add extra file validation here - check image type etc
        
    $upload_error false;
        foreach(
    $_FILES['images']['error'] as $error) {
            if (
    $error != && $error != 4) {
                
    $upload_error true;
            }
        }

        if (
    $upload_error) {
            
    $error_array[] = 'One of the image uploads failed!';
        }


        if (empty(
    $_POST['nome'])) {//if no nome has been supplied
            
    $error_array[] = 'Please enter a nome for your post.';//add to array "error"
        
    } else {
            
    $title $_POST['nome'];//else assign it a variable
        
    }

        if (empty(
    $_POST['descrizione'])) {
            
    $error_array[] = 'Please enter a descrizione of your post.';//add to array "error"
        
    } else {
            
    $desc $_POST['descrizione'];//else assign it a variable
        
    }

        if (empty(
    $_POST['prezzo'])) {
            
    $error_array[] = 'Please enter a prezzo of your post.';//add to array "error"
        
    } else {
            
    $desc $_POST['prezzo'];//else assign it a variable
        
    }

        if (empty(
    $error_array)){ //if no error, insert into db

            
    $new_post "INSERT INTO `prodotti` ( `nome`, `descrizione`, `prezzo`) VALUES (?, ?, ?)";
            
    $stmt $db->prepare($new_post);
            
    $stmt->execute(array($nome$descrizione$prezzo));

            
    $new_post_id $db->lastInsertId();

            
    // now start processing the images
            
    $image_sql "INSERT INTO `immagini` (`nome_immagine`, `id_prodotto`) VALUES (?, ?)";
            
    $stmt $db->prepare($image_sql);

            for (
    $i 1$i <= 6$i++) {

                
    // you need to add some code to validate, move and rename the files

                // add the files to the db
                
    $file_name $_FILES['images']['name'][$i];
                
    $stmt->execute(array($new_post_id$file_name));

            }

        } else {
            
    print_r($error_array);
        }

    }
    ?>

    <!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=utf-8" />
    <title>Inserisci Prodotto</title>
    </head>

    <body>
    <?php if (isset($show_errors)) { 
        
    //show user the errors if form cant be submitted
        
    echo '<div> <ol>';
            foreach (
    $error as $key => $values) { echo '    <li>'.$values.'</li>'; }
            echo 
    '</ol></div><br />'; }?>

    <br />
    <form method="post" id="newpost" action="" enctype="multipart/form-data">
    <div><input name="nome" type="text" value=""></div>
    <div><textarea id="area4" cols="40" rows="5" name="descrizione"></textarea></div>
    <div><input name="prezzo" type="text" value=""></div>
    <div><input type="file" name="images1"></div>
    <div><input type="file" name="images2"></div>
    <div><input type="file" name="images3"></div>
    <div><input type="file" name="images4"></div>
    <div><input type="file" name="images5"></div>
    <div><input type="file" name="images6"></div>
    <input type="hidden" name="formsubmitted" value="true" />
    <input type="submit" id="upload" value="Inserisci">
    </form>
    </body>
    </html>
    ricevo diversi notice riguardanti le righe 16, 49 e 62, ma soprattutto non ho nessun inserimento o nel DB e upload delle immagini. A proposito delle immagini, non ho capito dove va posiziona la cartella di upload e come va chiamata, nello script se ho capito bene è identificata come cartella images, o sbaglio?

    Quali potrebbero essere gli errori?
    Ultima modifica di harry80; 20-11-2013 a 10:08

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.