Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Problema con inserimento

    questa è la pagina:
    Codice PHP:
    <table>
        <form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST">
            <tr>
                <td>Title:</td>
                <td>
                    <input type="text" name="title" value="guida ai css" id="txtTitle" style="width: 250px;" />
                </td>
            </tr>
            <script type="text/javascript">
                var campo = new LiveValidation('txtTitle', { validMessage: "\u221a" });
                campo.add(Validate.Presence);
            </script>
            <tr>
                <td>Author:</td>
                <td>
                    <select name="author">
                        <option value="*">*</option>
                        <?php
                        
    foreach (selectAuthor () as $rowAuthor) {
                            echo 
    "<option value=\'" $rowAuthor['author_id'] . "'>" $rowAuthor['author_name'] . "</option>";
                        }
                        
    ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td>Editor:</td>
                <td>
                    <select name="editor">
                        <option value="*">*</option>
                        <?php
                        
    foreach (selectEditor () as $rowEditor) {
                            echo 
    "<option value='" $rowEditor['editor_id'] . "'>" $rowEditor['editor_name'] . "</option>";
                        }
                        
    ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td>Price:</td>
                <td>
                    <input type="text" name="price" value="0" id="txtPrice" />
                </td>
            </tr>
            <script type="text/javascript">
                var num = new LiveValidation('txtPrice', { validMessage: "\u221a" });
                num.add(Validate.Numericality);
            </script>
            <tr>
                <td>Isbn:</td>
                <td>
                    <input type="text" name="isbn" value="" />
                </td>
            </tr>
            <tr>
                <td>
                    Note:
                </td>
                <td>
                    <textarea name="note" rows="6" cols="40">
                    </textarea>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="submit" value="Submit" name="Submit" />
                </td>
            </tr>
        </form>
    </table>

    <?php
                        
    if ($_SERVER['REQUEST_METHOD'] == "POST") {
                            if (
    $_POST['title'] == NULL) {
                                echo 
    'Insert a title';
                            } elseif (
    $_POST['author'] == "*") {
                                echo 
    'Insert an author';
                            } elseif (
    $_POST['editor'] == "*") {
                                echo 
    'Insert an editor';
                            } elseif (!
    is_numeric($_POST['price'])) {
                                echo 
    'Price is not a number';
                            } else {
                                try {
                                    
    $prepare $config->getPdo()->prepare("INSERT book (title, author_id, editor_id, price, isbn, note) VALUES (?,?,?,?,?,?)");
                                    
    $prepare->execute(array(
                                        
    strtolower(trim($_POST['title'])),
                                        
    strtolower(trim($_POST['author'])),
                                        
    strtolower(trim($_POST['editor'])),
                                        
    strtolower(trim($_POST['price'])),
                                        
    strtolower(trim($_POST['isbn'])),
                                        
    strtolower(trim($_POST['note']))
                                    ));
                                    
    //header('location:[url]http://62.94.208.157/book/index.php[/url]');
                                
    } catch (Exception $e) {
                                    die(
    $e->getMessage());
                                }
                            }
                        }
    ho usato la stessa tecnica su altre pagine: insert/update autori/editori, update book, login.
    funzionano tutte tranne questa.
    una volta superati i controlli normali sembra che esegue la query ma poi nn aggiunge nulla nel db.
    la query è giusta perchè l'ho appena usata in un programma fatto in java.
    sono 2 ore che cerco l'errore.

  2. #2
    ho notato anche un'altra cosa strana.
    provo a fare l'inserimento da questa pagina.
    nn succede nulla.
    apro il programma java e inserisco il libro.
    controllo gli id della tabella e vedo che il campo id è stato incrementato lo stesso anche se nn è stato inserito nulla.

    nn avete qualche idea??

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.