Navigazione

    Privacy - Termini e condizioni
    © 2020 Search On Media Group S.r.l.
    • Registrati
    • Accedi
    • CATEGORIES
    • Discussioni
    • Non letti
    • Recenti
    • Hashtags
    • Popolare
    • Utenti
    • Stream
    • Interest
    • Categories
    1. Home
    2. geysermill
    3. Post
    G

    geysermill

    @geysermill

    • Profilo
    • Chi segue 0
    • Da chi è seguito 0
    • Discussioni 1
    • Post 3
    • Migliore 0
    • Gruppi 0
    Iscrizione Ultimo Accesso
    Località Brescia
    0
    Reputazione
    3
    Post
    0
    Visite al profilo
    0
    Da chi è seguito
    0
    Chi segue
    User Newbie

    Post creati da geysermill

    • RE: Problema update database

      Ciao Flavio,
      ho inserito il codice da te suggerito dopo "$msg = 'Aggiornata correttamente!';" e mi stampa: bool(false).
      Inoltre nel file error_log ho questo errore:
      PHP Warning: PDOStatement::execute() expects parameter 1 to be array, string given in /home/uqplaxvd/public_html/crm2020/update.php on line 18

      Inserendo solo "$pdo->errorInfo();" dopo "$msg = 'Aggiornata correttamente!';" mi da questo errore nel file error_log:
      PHP Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /home/uqplaxvd/public_html/crm2020/update.php on line 16

      Ho eliminato "ID = ?"
      Grazie per il supporto.

      postato in Coding
      G
      geysermill
    • RE: Problema update database

      Grazie.

      • <?php

      • include 'functions.php';

      • $pdo = pdo_connect_mysql();

      • $msg = '';

      • // Check if the commessa ID exists, for example update.php?ID=1 will get the commessa with the ID of 1

      • if (isset($_GET['ID'])) {

      • if (!empty($_POST)) {
        
      •     // This part is similar to the create.php, but instead we update a record and not insert
        
      •     $id = isset($_POST['ID']) ? $_POST['ID'] : NULL;
        
      •     $data = isset($_POST['data']) ? $_POST['data'] : date('Y-m-d');
        
      •     $clienti = isset($_POST['clienti']) ? $_POST['clienti'] : '';
        
      •     $descrizione = isset($_POST['descrizione']) ? $_POST['descrizione'] : '';
        
      •     $quantita = isset($_POST['quantita']) ? $_POST['quantita'] : '';
        
      •     // Update the record
        
      •     $stmt = $pdo->prepare('UPDATE commesse_2020 SET ID = ?, data = ?, clienti = ?, descrizione = ?, quantita = ?, WHERE ID = ?');
        
      •     $stmt->execute([$id, $data, $clienti, $descrizione, $quantita, $_GET['ID']]);
        
      •     $msg = 'Aggiornata correttamente!';
        
      • }
        
      • // Get the commessa from the commesse table
        
      • $stmt = $pdo->prepare('SELECT * FROM commesse_2020 WHERE ID = ?');
        
      • $stmt->execute([$_GET['ID']]);
        
      • $commessa = $stmt->fetch(PDO::FETCH_ASSOC);
        
      • if (!$commessa) {
        
      •     exit('La commessa non esiste con questo ID!');
        
      • }
        
      • } else {

      • exit('No ID specified!');
        
      • }

      • ?>

      • <?=template_header('Read')?>

      • <div class="content update">

      • <h2>Modifica commessa #<?=$commessa['ID']?></h2>
        
      • <form action="update.php?ID=<?=$commessa['ID']?>" method="post">
        
      •   <label for="ID">ID</label>
        
      •   <input type="text" name="ID" placeholder="26" value="auto" ID="ID">
        
      •   <label for="data">data</label>
        
      •   <input type="datetime-local" name="data" value="<?=date('Y-m-d')?>" ID="data">
        
      •   <label for="clienti">clienti</label>
        
      •   <input type="text" name="clienti" placeholder="Nome cliente" ID="clienti">
        
      •   <label for="descrizione">descrizione</label>
        
      •   <input type="text" name="descrizione" placeholder="Descrizione" ID="descrizione">
        
      •   <label for="quantita">quantita</label>
        
      •   <input type="text" name="quantita" placeholder="Quantita" ID="quantita">
        
      •     <input type="submit" value="Update">
        
      • </form>
        
      • <?php if ($msg): ?>
        
      • <p><?=$msg?></p>
        
      • <?php endif; ?>
        
      • </div>

      • <?=template_footer()?>

      postato in Coding
      G
      geysermill
    • Problema update database

      Buongiorno,
      sono alle prime armi con php e sto impostando un semplice CRUD.
      Ho un problema con il file update che non mi fa aggiornare i dati del database. Non si genera nessun error_log e quando modifico i dati nel browser, il sistema mi dice che sono aggiornati correttamente ma non vengono modificati. Tutto il resto funziona. Riuscite a darmi un aiuto per favore? Di seguito il codice.
      Grazie. Francesco.
      [PHP]<?phpinclude 'functions.php';$pdo = pdo_connect_mysql();$msg = '';// Check if the commessa ID exists, for example update.php?ID=1 will get the commessa with the ID of 1if (isset($_GET['ID'])) { if (!empty($_POST)) { // This part is similar to the create.php, but instead we update a record and not insert $id = isset($_POST['ID']) ? $_POST['ID'] : NULL; $data = isset($_POST['data']) ? $_POST['data'] : date('Y-m-d'); $clienti = isset($_POST['clienti']) ? $_POST['clienti'] : ''; $descrizione = isset($_POST['descrizione']) ? $_POST['descrizione'] : ''; $quantita = isset($_POST['quantita']) ? $_POST['quantita'] : ''; // Update the record $stmt = $pdo->prepare('UPDATE commesse_2020 SET ID = ?, data = ?, clienti = ?, descrizione = ?, quantita = ?, WHERE ID = ?'); $stmt->execute([$id, $data, $clienti, $descrizione, $quantita, $_GET['ID']]); $msg = 'Aggiornata correttamente!'; } // Get the commessa from the commesse table $stmt = $pdo->prepare('SELECT * FROM commesse_2020 WHERE ID = ?'); $stmt->execute([$_GET['ID']]); $commessa = $stmt->fetch(PDO::FETCH_ASSOC); if (!$commessa) { exit('La commessa non esiste con questo ID!'); }} else { exit('No ID specified!');}?>
      <?=template_header('Read')?>
      <div class="content update"> <h2>Modifica commessa #<?=$commessa['ID']?></h2> <form action="update.php?ID=<?=$commessa['ID']?>" method="post"> <label for="ID">ID</label> <input type="text" name="ID" placeholder="26" value="auto" ID="ID"> <label for="data">data</label> <input type="datetime-local" name="data" value="<?=date('Y-m-d')?>" ID="data"> <label for="clienti">clienti</label> <input type="text" name="clienti" placeholder="Nome cliente" ID="clienti"> <label for="descrizione">descrizione</label> <input type="text" name="descrizione" placeholder="Descrizione" ID="descrizione"> <label for="quantita">quantita</label> <input type="text" name="quantita" placeholder="Quantita" ID="quantita"> <input type="submit" value="Update"> </form> <?php if ($msg): ?> <p><?=$msg?></p> <?php endif; ?></div>
      <?=template_footer()?>
      [/PHP]

      postato in Coding
      G
      geysermill