Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    May 2009
    Messaggi
    33

    modifica record con campo id non modificabile

    Ciao a tutti ho un piccolo problema con la modifica dei record.
    Io voglio fare in modo che quando entro nel form per modificare il campo id non sia modificabile solo che quando modifico qlc mi da errore di sintassi...non riesce a prendermi l'id dell'appuntamento.

    Se invece metto anche nel campo id l'input text mi funziona perfettamente.

    Ecco il codice dove l'id non viene inserito in una textbox, quindi non modificabile.

    Codice PHP:

    <?php

        $confirm
    =$_REQUEST['confirm'];
        
    $id_appuntamento=$_REQUEST['id_appuntamento'];
        
        if (!
    $confirm)
        {
            
    $dati=mysql_fetch_array(mysql_query("SELECT * FROM appuntamenti WHERE id_appuntamento=$id_appuntamento")); 
            
    //$sql="select * from appuntamenti where id_appuntamento=".$id_appuntamento;
            //$result = mysql_query($sql, $db) or die (mysql_error());
            
    $AffectedRows mysql_affected_rows($db);
            
            if (
    $AffectedRows==0)
            {
                echo 
    "Non esistono record con i criteri selezionati";
            }
            else
            {
            
    ?>    


    <h2>Modifica dati appuntamento</h2>




    <table>
        <form method="post" action="?indice=27">
            <tr><td> Id </td>
                <td><name="id_appuntamento"><?php echo $id_appuntamento?></td>
            </tr>
            <tr><td> Oggetto </td>
                <td><input type="text" name="oggetto" size="40" value="<?php echo $dati['oggetto_appuntamento']; ?>" /></td>
            </tr>

            <tr><td> Data </td>
                <td><input type="text" name="data" size="40" value="<?php echo $dati['data_appuntamento']; ?>" /></td>
            </tr>
            
            <tr><td> Lingua </td>
                <td><input type="text" name="linguaappuntamenti" size="40" value="<?php echo $dati['id_lingua']; ?>" /></td>
            </tr>
            
            <tr><td> Testo </td>
                <td>
                    <name="testo">
                    <?php
                        $oFCKeditor 
    = new FCKeditor('FCKeditor1') ;
                        
    $oFCKeditor->BasePath 'fckeditor/' ;
                        
    // Value diventa il testo estratto dal DATABASE
                        
    $oFCKeditor->Value $dati['testo_appuntamento'];
                        
    $oFCKeditor->Width  "565px";
                        
    $oFCKeditor->Height "350px";
                        
    $oFCKeditor->Create() ;
                    
    ?>
                    
                </td>
            </tr>
            
            <tr><td> Data_reg </td>
                <td><input type="text" name="data_registrazione" size="40" value="<?php echo $dati['data_registrazione_appuntamento']; ?>" /></td>
            </tr>
                    
                    
            <tr><td></td><td><input type="submit" value="Conferma modifiche"></td></tr>
            <input type="hidden" name="confirm" value="1">
        </form>                
    </table>
        
    <?            

            
    //mysql_free_result($result);
            
    mysql_close($db);
            }
        }
        else
        {
            
    $data_registrazione date("Y-m-d H:i:s");
            
            
    $oggetto=$_REQUEST['oggetto'];
            
    $data $_REQUEST['data'];
            
    $linguaappuntamenti=$_REQUEST['linguaappuntamenti'];
            
    $testo mysql_real_escape_string(trim($_REQUEST['FCKeditor1']));
            
            
    $sql="update appuntamenti set oggetto_appuntamento='$oggetto', data_appuntamento='$data', id_lingua='$linguaappuntamenti', testo_appuntamento='$testo', data_registrazione_appuntamento='$data_registrazione' where id_appuntamento = $id_appuntamento";
            
            
    var_dump($sql);
            
            
    $result mysql_query($sql$db) or die("errore:".mysql_error());
            
    $AffectedRows mysql_affected_rows($db);
            
            if (
    $AffectedRows!=0)
            {
                echo 
    "Il record &egrave; stato aggiornato";
                echo 
    "<a href=\"?indice=24\">Torna alla lista</a>";
            }
            
    mysql_close($db);
        }
    ?>

    Qualcuno sa dirmi come fare per poter appunto aggiornare i dati senza che l'id si trovi dentro in una textbox?

    Spero di essere stato chiaro.
    Grazieeeee

  2. #2
    Utente di HTML.it L'avatar di r1cky`
    Registrato dal
    Feb 2007
    Messaggi
    431
    Io ti consiglio di mettere l'id in un campo di tipo hidden, in modo che l'utente non lo veda proprio!

    codice:
    <input type="hidden" value="<?php echo $id_appuntamento; ?>">
    Chiaramente poi il codice per la riga e la colonna non ti servono più

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2009
    Messaggi
    33
    funziona

    ecco il codice

    Codice PHP:

    <?php



        $confirm
    =$_REQUEST['confirm'];
        
        
    $id_appuntamento $_REQUEST['id_appuntamento'];
        

        if (!
    $confirm)
        {
            
    $dati=mysql_fetch_array(mysql_query("SELECT * FROM appuntamenti WHERE id_appuntamento=$id_appuntamento")); 
            
            
    $AffectedRows mysql_affected_rows($db);
            
            if (
    $AffectedRows==0)
            {
                echo 
    "Non esistono record con i criteri selezionati";
            }
            else
            {
            
    ?>    


    <h2>Modifica dati appuntamento</h2>




    <table>
        <form method="post" action="?indice=27">
            
            <tr><td> Oggetto </td>
                <td><input type="text" name="oggetto" size="40" value="<?php echo $dati['oggetto_appuntamento']; ?>" /></td>
            </tr>

            <tr><td> Data </td>
                <td><input type="text" name="data" size="40" value="<?php echo $dati['data_appuntamento']; ?>" /></td>
            </tr>
            
            <tr><td> Lingua </td>
                <td><input type="text" name="linguaappuntamenti" size="40" value="<?php echo $dati['id_lingua']; ?>" /></td>
            </tr>
            
            <tr><td> Testo </td>
                <td>
                    <name="testo">
                    <?php
                        $oFCKeditor 
    = new FCKeditor('FCKeditor1') ;
                        
    $oFCKeditor->BasePath 'fckeditor/' ;
                        
    // Value diventa il testo estratto dal DATABASE
                        
    $oFCKeditor->Value $dati['testo_appuntamento'];
                        
    $oFCKeditor->Width  "565px";
                        
    $oFCKeditor->Height "350px";
                        
    $oFCKeditor->Create() ;
                    
    ?>
                    
                </td>
            </tr>
            
            <tr><td> Data_reg </td>
                <td><input type="text" name="data_registrazione" size="40" value="<?php echo $dati['data_registrazione_appuntamento']; ?>" /></td>
            </tr>
                    
                    
            <tr><td></td><td><input type="submit" value="Conferma modifiche"></td></tr>
            <input type="hidden" name="confirm" value="1">
            <input type="hidden" name="id_appuntamento" value="<?php echo $id_appuntamento?>">
        </form>                
    </table>
        
    <?            

            
    //mysql_free_result($result);
            
    mysql_close($db);
            }
        }
        else
        {
            
    $data_registrazione date("Y-m-d H:i:s");
            
            
    $oggetto=$_REQUEST['oggetto'];
            
    $data $_REQUEST['data'];
            
    $linguaappuntamenti=$_REQUEST['linguaappuntamenti'];
            
    $testo mysql_real_escape_string(trim($_REQUEST['FCKeditor1']));
            
            
            
    $sql="update appuntamenti set oggetto_appuntamento='$oggetto', data_appuntamento='$data', id_lingua='$linguaappuntamenti', testo_appuntamento='$testo', data_registrazione_appuntamento='$data_registrazione' where id_appuntamento = $id_appuntamento";
            
            
    //var_dump($sql);
            
            
    $result mysql_query($sql$db) or die("errore:".mysql_error());
            
    $AffectedRows mysql_affected_rows($db);
            
            if (
    $AffectedRows!=0)
            {
                echo 
    "Il record &egrave; stato aggiornato";
                echo 
    "<a href=\"?indice=24\">Torna alla lista</a>";
            }
            
    mysql_close($db);
        }


    ?>
    GRAZIE

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.