Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 12

Discussione: Timynce e Mysql

  1. #1

    Timynce e Mysql

    Devo rendere le pagine di un sito modificabili tramite browser per tale motivo ho usato Timynce, PHP e Mysql.
    Se le pagine sono di solo testo e non troppo lungo l'update funzione.
    Invece se le pagine hanno immagini, hr, ul o altri non di testo e sono lunghe non esegue l'update.

    Aiuto

  2. #2
    Utente di HTML.it L'avatar di homerbit
    Registrato dal
    Dec 2005
    residenza
    Roma
    Messaggi
    1,380
    che errore ti ritorna l'update?
    probabilmente non fai un "sanitize" delle varie stringhe che vorresti inserire nel db
    If you think your users are idiots, only idiots will use it. DropBox

  3. #3
    Originariamente inviato da homerbit che errore ti ritorna l'update?
    Nessun errore. Non mi salva le correzioni.
    Originariamente inviato da homerbit
    probabilmente non fai un "sanitize" delle varie stringhe che vorresti inserire nel db
    Cosa intendi per sanitize?

  4. #4
    Utente di HTML.it L'avatar di homerbit
    Registrato dal
    Dec 2005
    residenza
    Roma
    Messaggi
    1,380
    rendere sicuri i dati che inserisci nel db
    If you think your users are idiots, only idiots will use it. DropBox

  5. #5

    Errore: SQLSTATE[42000]

    Codice PHP:
    <?php 
    $host 
    'localhost';    $username 'root';    $password '';    $name 'prova'
    try {
    $db = new PDO('mysql:host=' .$host ';dbname=' .$name$username$password);         $db->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
    }
    catch(
    PDOException $e) {
    echo 
    '<h3>
    Catch Connect Error--->>> '  
    $e->getMessage() . '
    </h3>'
    ;           return false;  } 
    $query 'SELECT * FROM pagine WHERE nome LIKE \'prova\'    ';
    $result $db->query($query);
    $result->fetch(PDO::FETCH_ASSOC)) {
    echo 
    '<form  id="pagina_mod" action=\'\' method="post">
    <textarea name="testo" id="testo" rows="10" cols="132" tabindex="1">'
    .$row['testo']    .'</textarea>
     <input type="hidden" name="nome"  value="'
    .$row['nome'].'" /> 
    <span class="col2 testo_centro"><a href=\'gestione_page.php\' ><input type="submit" name="annulla" value="Annulla" /></a></span>         <span class="col2 testo_centro">
    <input type="submit" name="submit" value="Salva" /></span></form>'
    ;  }
     if (isset(
    $_POST['nome']))
    {
    $query 'UPDATE pagine SET testo = \''.$_POST['testo'].'\' WHERE nome LIKE \''.$_POST['nome'].'\'';  
    try{
    $db->beginTransaction();
    $sql $query$stmt $db->prepare($sql);
    $stmt->bindParam(':testo'$_POST['testo']);
    $stmt->execute(); $result $db->commit(); }
    catch (
    PDOException $e)
    { echo 
    'Si &egrave; verificata una PDO Exception.'; echo 'SQL Query: '$sql; echo 'Errore: ' $e->getMessage(); } 
     }
    $result->closeCursor();
    $db null;?>
    Come dice all'inizio l'update non funziona se il testo ha tag img, hr, ul ecc. e il testo è lungo.

    Mi da questo, errore:
    codice:
    Errore: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server

  6. #6
    Utente di HTML.it L'avatar di boots
    Registrato dal
    Oct 2012
    Messaggi
    1,626
    Così come fai tu, non viene fatto l'escape dei parametri.
    Dovresti far così:

    Codice PHP:
    $query 'UPDATE pagine SET testo = :testo WHERE nome LIKE :nome';   
    try{
        ...
        
    $stmt->bindParam(':testo'$_POST['testo']); 
        
    $stmt->bindParam(':nome'$_POST['nome']); 
        
    $stmt->execute(); 
        
    $result $db->commit(); 


  7. #7
    Originariamente inviato da boots
    Così come fai tu, non viene fatto l'escape dei parametri.
    Dovresti far così:

    Codice PHP:
    $query 'UPDATE pagine SET testo = :testo WHERE nome LIKE :nome';   
    try{
        ...
        
    $stmt->bindParam(':testo'$_POST['testo']); 
        
    $stmt->bindParam(':nome'$_POST['nome']); 
        
    $stmt->execute(); 
        
    $result $db->commit(); 

    Purtroppo mi da ancora
    codice:
    Errore: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server

  8. #8
    Utente di HTML.it L'avatar di boots
    Registrato dal
    Oct 2012
    Messaggi
    1,626
    La query mi sembra corretta, non saprei ....

    Sicuro sia quella che ti va in errore ?

  9. #9
    Prova a passare il terzo parametro alla funzione "bindParam".
    quindi modifica
    Codice PHP:
    $stmt->bindParam(':testo'$_POST['testo']); 
    $stmt->bindParam(':nome'$_POST['nome']); 
    in
    Codice PHP:
    $stmt->bindParam(':testo'$_POST['testo'],PDO::PARAM_STR); 
    $stmt->bindParam(':nome'$_POST['nome'],PDO::PARAM_STR); 
    Anche se in effetti non passandolo, prende già di default il tipo stringa.
    CODENCODE \ Branding \ Design \ Marketing
    www.codencode.it

  10. #10
    l'errore è proprio un problema di parsing dell'sql, quindi qualcosa di sbagliato quando compone la query. Solo che mi pare strano che continui a dartelo in quel contesto. Sicuro che quello che ci mostri è il codice utilizzato e che l'errore sia in quel punto li?
    IP-PBX management: http://www.easypbx.it

    Old account: 2126 messages
    Oldest account: 3559 messages

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.