Visualizzazione dei risultati da 1 a 6 su 6

Discussione: update non funziona

  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2007
    Messaggi
    216

    update non funziona

    Salve, ho un problema con uno script php: la funzione update non modifica il database ma
    i vari record rimangono sempre gli stessi. Qualcuno può aiutarmi?

    Questo è il codice:

    <form method="post" action="modifica-prodotto.php">
    <table width="90%" border="0" cellpadding="8">
    <tr style="vertical-align: top">
    <td width="10%" style="text-align: right">
    <label class="etichetta">Codice</label> </td>
    <td colspan="2">
    <input type="text" name="codice"></td> </tr>
    <tr style="vertical-align: top">
    <td style="text-align: right">
    <label class="etichetta">Nome</label> </td>
    <td colspan="2"> <input type="text" name="nome" size="30"> </td>
    </tr>
    <tr style="vertical-align: top"> </tr>
    <tr style="vertical-align: top">
    <td style="text-align: right"> <label class="etichetta">Descrizione</label> </td>
    <td width="87%">
    <textarea name="descrizione" cols="46" rows="4"></textarea></td>

    </tr>
    <tr style="vertical-align: top">
    <td style="text-align: right">
    <label class="etichetta">Immagine</label></td>
    <td colspan="2"><input name="immagine" type="file" size="30"></td>
    </tr>
    <tr style="vertical-align: top">
    <td style="text-align: right"> <label class="etichetta">Prezzo</label></td>
    <td colspan="2"> <input name="prezzo" type="text"> </td>

    </tr>
    </table>
    <table width="566" cellspacing="0" cellpadding="0">
    <tr>
    <td height="50" align="left"></td>
    <td width="90" height="50" align="center"></td>
    <td width="73" height="50"></td>
    <td width="73" height="50" align="center"></td>
    <td width="73" height="50"></td>
    <td width="87" height="50" align="center"><button type="submit" name="modifica">[img]../immagini/invia.png[/img]</button></td>
    <td width="18" height="50"></td>
    <td width="95" height="50" align="center"><button type="reset" name="annulla">[img]../immagini/cancel.png[/img]</button></td>
    <td width="63" height="50"></td>
    </tr>
    <tr>
    <td width="5" height="30"></td>
    <td height="30" align="left"></td>
    <td width="73" height="30" align="center"></td>
    <td width="73" height="30"></td>
    <td width="73" height="30" align="center"></td>
    <td width="87" height="30"><div align="center">Modifica
    </div></td>
    <td width="18" height="30" align="center"></td>
    <td width="95" height="30"><div align="center">Annulla</div></td>
    </tr>
    </table>
    </form>
    <?php
    include "../config_db.php";
    if (isset($_POST['modifica'])){
    $id_prodotto = $_POST['id_prodotto'];
    $codice = $_POST['codice'];
    $nome = $_POST['nome'];
    $descrizione = $_POST['descrizione'];
    $immagine = $_POST['immagine'];
    $prezzo = $_POST['prezzo'];
    $sql = "UPDATE prodotti SET codice = '$codice', nome = '$nome', descrizione = '$descrizione', immagine = '$immagine', prezzo = '$prezzo' WHERE id_prodotto = '$id_prodotto'";
    $res = mysql_query($sql) OR DIE ("
    Errore Numero: ".mysql_errno() ."
    Descrizione: ". mysql_error()."<hr />");

    echo "<script type=\"text/javaScript\">";
    echo "alert(\"Prodotto modificato!\")";
    echo "</script>";

    }
    ?>

  2. #2
    Utente di HTML.it L'avatar di Ranma2
    Registrato dal
    Mar 2003
    Messaggi
    2,648
    controlla che ci siano tutte le variabili, fai un echo slla variabile $sql così hai un riscontro veloce su cosa manca

  3. #3
    Codice PHP:
    $id_prodotto $_POST['id_prodotto']; 
    dove valorizzi nel form "id_prodotto" ????


    Sarebbe pero' meglio postare il codice tra tag [php ] oppure [code ] per agevolare la lettura.

    come fare cio' ?

    http://forum.html.it/forum/misc.php?...bbcode#buttons

    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

  4. #4
    Utente di HTML.it
    Registrato dal
    Oct 2007
    Messaggi
    216
    Forse bisogna usare un campo hidden?

  5. #5
    Utente di HTML.it L'avatar di Ranma2
    Registrato dal
    Mar 2003
    Messaggi
    2,648
    Originariamente inviato da Bruce5000
    Forse bisogna usare un campo hidden?
    direi di si, se non gli passi il campo id del prodotto non può sapere dove deve andare a scrivere

  6. #6
    Utente di HTML.it
    Registrato dal
    Oct 2007
    Messaggi
    216
    Mi puoi spiegare come devo fare?

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.