Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 19
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2008
    Messaggi
    29

    Inserimento commenti in php problema

    ciao ragazzi, ho un problema che non riesco a risolvere Devo inserire dei commenti nel mio database in una specifica tabella commenti dopo gli attributi sono:
    id
    testo
    username(user dell'utente che ha commentato)
    articolo(l'articolo che voglio commentare)

    ho una pagina commenti.php che richiama l'id dell'articolo dalla pagina index e lo user dell'utente loggato, entrambi questi valori li passerò hidden e li inserirò nella tabella, ho fatto un form di inserimento ma mi esce questo errore
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1..

    Vi posto il codice di commenti.php:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Untitled</title>
    </head>
    <body>
    <?
    //connessione al database e seleziono l'articolo da commentare
    include "connessione.php";
    $id=$_GET['art'];
    $usern=$_GET['user'];
    $query_searchnewart = "SELECT * from articolo where ID=$id";
    $searchnewart = mysql_query($query_searchnewart) or die(mysql_error());
    $row_searchnewart = mysql_fetch_assoc($searchnewart);
    $totalRows_searchnewart = mysql_num_rows($searchnewart);
    $query_user = "SELECT * FROM membro where username='$usern'";
    $user = mysql_query($query_user) or die(mysql_error());
    $row_user = mysql_fetch_assoc($user);
    $totalRows_user = mysql_num_rows($user);
    echo "


    <FORM ACTION ='$_SERVER[PHP_SELF]' method='POST'>



    <INPUT type='textarea' name='testo' maxlength='36' size='36' value='$testo'> (Solo numeri)</p>




    <INPUT type='hidden' name='usern' maxlength='50' size='50' value='$usern'></p>




    <INPUT type='hidden' name='articolo' maxlength='30' size='30' value='$id'></p>

    <INPUT type='SUBMIT' value='Invia'>
    <INPUT type='RESET' value='Cancella'>
    </FORM></p>";


    $testo=$_POST["testo"];
    $usern=$_POST['usern'];
    $id=$_POST['articolo'];


    // INSERIMENTO
    $stringa = "INSERT INTO commenti (id,testo,username,articolo ) VALUES ";
    $stringa .= "( '','$testo','$usern','$id' )";
    ?>
    <?php
    if ( !mysql_query ( $stringa ) )
    {
    echo ( "ERRORE: nell' inserimento commenti");
    exit();
    }
    else{
    echo "commento inserito correttamente";
    }
    mysql_close( $conn );



    ?>
    </body>
    </html>

    spero di avere una risposta grazie!

  2. #2
    Utente di HTML.it
    Registrato dal
    Jul 2003
    Messaggi
    613
    Tiro ad indovinare, nel testo che inserisci ci sono apici!
    Conosci te stesso(?)
    (..e allora perchè scassi a me? )

  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2008
    Messaggi
    29
    Non ci sono apici e comunque nel caso ci fossero ci sarebbe la funzione str_replace per sostiturli il problema è un altro e non so proprio quale

  4. #4
    Utente di HTML.it
    Registrato dal
    Jul 2003
    Messaggi
    613
    E allora ti consiglio di postare l'intero errore e riga
    Conosci te stesso(?)
    (..e allora perchè scassi a me? )

  5. #5
    Utente di HTML.it L'avatar di Pastore12
    Registrato dal
    Oct 2008
    Messaggi
    1,051
    Penso che un'altro bel aiuto sarebbe di scrivere il contenuto della stringa sql prima di passarla al database.. ci sono un paio di virgolette che mi mandano in confusione..
    "Ethics are to me something private. Whenever you use it as an argument for why somebody_else should do something, you’re no longer being ethical, you’re just being a sanctimonious dick-head"
    Linus Torvalds

  6. #6
    Utente di HTML.it
    Registrato dal
    Oct 2008
    Messaggi
    29
    Quella pagina è l'intera pagina commenti.php con errore annesso al seguito non ho omesso niente!

  7. #7
    Utente di HTML.it
    Registrato dal
    Jul 2003
    Messaggi
    613
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1..
    Cioè la linea è 1?

    Pensavo che i puntini servissero ad indicare che manca un pezzo, tipo il resto della query.

    Comunque si, stampati anche la query che dà l'errore.
    Conosci te stesso(?)
    (..e allora perchè scassi a me? )

  8. #8
    Utente di HTML.it L'avatar di Pastore12
    Registrato dal
    Oct 2008
    Messaggi
    1,051
    Con qualcosa di questo tipo.. Ma perchè su echo ci metti le parentesi? Premetto che ora non posso testare il codice..

    Codice PHP:

        // INSERIMENTO
        $stringa = "INSERT INTO commenti (id,testo,username,articolo ) VALUES ";
        $stringa .= "( '','$testo','$usern','$id' )";
    ?>

    <?php
        
    if ( !mysql_query $stringa ) )
        {
            
            echo 
    "ERRORE: nell' inserimento commenti
    "
    ;
            echo 
    "sql: ".$stringa;
            exit();
        }
    "Ethics are to me something private. Whenever you use it as an argument for why somebody_else should do something, you’re no longer being ethical, you’re just being a sanctimonious dick-head"
    Linus Torvalds

  9. #9
    Utente di HTML.it
    Registrato dal
    Oct 2008
    Messaggi
    29
    ciao ho fatto come mi hai detto ma mi esce sempre:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

    Non ho capito perchè

  10. #10
    Utente di HTML.it
    Registrato dal
    Jul 2003
    Messaggi
    613
    stampa la stringa di query senza eseguire la query... e postala
    Conosci te stesso(?)
    (..e allora perchè scassi a me? )

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.