Visualizzazione dei risultati da 1 a 10 su 16

Hybrid View

  1. #1
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,372
    Prova questo.

    File : test319.php
    Codice PHP:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><?php 
    if (isset($_POST['bottone'])) {
     if (
    $_POST['bottone'] == "Invia") {
     
     foreach(
    $_POST['prodotto'] as $key => $value) {
      print 
    "prodotto chiave=$key valore=$value<br/>";
     } 
    // foreach($_POST['prodotto'] as $key => $value)
     
    print "<hr/>";
     foreach(
    $_POST['fornitore'] as $key => $value) {
      print 
    "fornitore chiave=$key valore=$value<br/>";
     } 
    // foreach($_POST['fornitore'] as $key => $value)
     
    print "<hr/>";
     foreach(
    $_POST['descrizione'] as $key => $value) {
      print 
    "descrizione chiave=$key valore=$value<br/>";
     } 
    // foreach($_POST['descrizione'] as $key => $value)
     
    print "<hr/>";
     foreach(
    $_POST['quantita'] as $key => $value) {
      print 
    "quantita chiave=$key valore=$value<br/>";
     } 
    // foreach($_POST['quantita'] as $key => $value)
     
    print "<hr/>";
     foreach(
    $_POST['prezzo'] as $key => $value) {
      print 
    "prezzo chiave=$key valore=$value<br/>";
     } 
    // foreach($_POST['prezzo'] as $key => $value)
     
    print "<hr/>";       
     } 
    // if ($_POST['bottone'] == "Invia")
    // if (isset($_POST['bottone'])) ?>
    <html>
    <head>
    <title>Untitled</title>
    </head>
    <body>
    <form action="test319.php" method="post">
     <table>
      <th>Prodotto</th><th>Fornitore</th><th>Descrizione</th><th>Quantita</th><th>Prezzo</th><?php 
      $i
    =1;
      for(
    $i=1;$i<=10;$i++) { ?>
     <tr>
      <td><input type="text" name="prodotto[]" /></td>
      <td><input type="text" name="fornitore[]" /></td>
      <td><input type="text" name="descrizione[]" /></td>
      <td><input type="text" name="quantita[]" /></td>
      <td><input type="text" name="prezzo[]" /></td>
     </tr><?php 
     
    // for($i=1;$i<=10;$i++) ?>
     </table>
     <input type="submit" value="Invia" name="bottone" />
    </form>
    </body>
    </html>
    Capito il concetto ?
    Ridatemi i miei 1000 posts persi !!!!
    Non serve a nulla ottimizzare qualcosa che non funziona.
    Cerco il manuale dell'Olivetti LOGOS 80B - www.emmella.fr

  2. #2
    Quote Originariamente inviata da badaze Visualizza il messaggio
    Prova questo.

    File : test319.php
    Codice PHP:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><?php 
    if (isset($_POST['bottone'])) {
     if (
    $_POST['bottone'] == "Invia") {
     
     foreach(
    $_POST['prodotto'] as $key => $value) {
      print 
    "prodotto chiave=$key valore=$value<br/>";
     } 
    // foreach($_POST['prodotto'] as $key => $value)
     
    print "<hr/>";
     foreach(
    $_POST['fornitore'] as $key => $value) {
      print 
    "fornitore chiave=$key valore=$value<br/>";
     } 
    // foreach($_POST['fornitore'] as $key => $value)
     
    print "<hr/>";
     foreach(
    $_POST['descrizione'] as $key => $value) {
      print 
    "descrizione chiave=$key valore=$value<br/>";
     } 
    // foreach($_POST['descrizione'] as $key => $value)
     
    print "<hr/>";
     foreach(
    $_POST['quantita'] as $key => $value) {
      print 
    "quantita chiave=$key valore=$value<br/>";
     } 
    // foreach($_POST['quantita'] as $key => $value)
     
    print "<hr/>";
     foreach(
    $_POST['prezzo'] as $key => $value) {
      print 
    "prezzo chiave=$key valore=$value<br/>";
     } 
    // foreach($_POST['prezzo'] as $key => $value)
     
    print "<hr/>";       
     } 
    // if ($_POST['bottone'] == "Invia")
    // if (isset($_POST['bottone'])) ?>
    <html>
    <head>
    <title>Untitled</title>
    </head>
    <body>
    <form action="test319.php" method="post">
     <table>
      <th>Prodotto</th><th>Fornitore</th><th>Descrizione</th><th>Quantita</th><th>Prezzo</th><?php 
      $i
    =1;
      for(
    $i=1;$i<=10;$i++) { ?>
     <tr>
      <td><input type="text" name="prodotto[]" /></td>
      <td><input type="text" name="fornitore[]" /></td>
      <td><input type="text" name="descrizione[]" /></td>
      <td><input type="text" name="quantita[]" /></td>
      <td><input type="text" name="prezzo[]" /></td>
     </tr><?php 
     
    // for($i=1;$i<=10;$i++) ?>
     </table>
     <input type="submit" value="Invia" name="bottone" />
    </form>
    </body>
    </html>
    Capito il concetto ?
    Ok, grazie infinite per l'esempio ora mi resta solo una cosa da capire

    io per inserire i dati in tabella, valorizzo prima le variabili tipo::

    codice:
    ...
    ...
    foreach($_POST['prezzo'] as $key => $value)
    {
    $this->prezzo = $_POST['prezzo'];
    print "prezzo chiave=$key valore=$value<br/>";
    } 
                    
                        $dipendente = $_SESSION['id'];
                        
                        $query = "
                                    INSERT INTO workpaper
                                    SET 
                                        prodotto='".mysql_real_escape_string($this->prodotto)."',
                                        fornitore='".mysql_real_escape_string($this->fornitore)."',
                                        descrizione='".mysql_real_escape_string($this->descrizione)."',
                                        quantita='".mysql_real_escape_string($this->quantita)."',
                                        prezzo='".mysql_real_escape_string($this->prezzo)."',
                                        dipendente='".mysql_real_escape_string($dipendente)."'
                                        ";
    Il problema è che ottengo questo messaggio:

    Warning: mysql_real_escape_string() expects parameter 1 to be string, array given

    che si presenta proprio alla prima riga della query, effettivamente si aspetta una stringa e non un array.
    ?

  3. #3
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,509
    Quote Originariamente inviata da wormd Visualizza il messaggio
    ...
    che si presenta proprio alla prima riga della query, effettivamente si aspetta una stringa e non un array.
    E quindi sai cosa c'è che non va, vuole una stringa e tu gli stai passando un array.

  4. #4
    Quote Originariamente inviata da Alhazred Visualizza il messaggio
    E quindi sai cosa c'è che non va, vuole una stringa e tu gli stai passando un array.
    Ciao,

    aggiungendo
    codice:
    prodotto='".mysql_real_escape_string(serialize($prodotto))."',
    In tabella poi mi ritrovo nella stessa riga a:2:{i:0;s:5:"prova1";i:1;s:5:"prova2";}

    mentre dovrebbe creare più righe per tutti i prodotti creati dinamicamente.
    ?

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.