Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 13
  1. #1
    Utente di HTML.it L'avatar di gaten
    Registrato dal
    Jul 2007
    Messaggi
    1,269

    Filtrare un campo di testo

    Come posso "filtrare" completamente un testo nel quale ho virgole , apici etc... , questo contenuto va all'interno di una query insert.
    ho provato ad usare htmlspecialchars, htmlentities ed addslashes, ma mi dà sempre errore nella query.
    Con i sogni possiamo conoscere il futuro...

  2. #2
    Utente di HTML.it
    Registrato dal
    May 2011
    Messaggi
    762
    Dipende come le usi.

    htmlentities ad esempio si può comportare in modo diverso a seconda se la usi "secca" o se specifichi gli altri parametri.

    Ti consiglio di effettuare delle prove per tutte le versioni. E, ad ogni modo, prima di ogni inserimento in database usa la funzione PHP mysql_real_escape_string().

    E comunque posta il codice che magari può essere che sbagli qualcosa lì..

  3. #3
    Utente di HTML.it L'avatar di gaten
    Registrato dal
    Jul 2007
    Messaggi
    1,269
    La query è questa:

    Codice PHP:
    $query "INSERT INTO muzik (name, facebook, myspace, advisor, website, image, soundcloud, bio, type)
              VALUES ('
    $name', '$facebook', '$myspace', '$advisor', '$website', '".$image."', '$soundcloud', '$bio', '$type')"

    io gli passo tutti i valori però mi dà errore quando inserisco questo testo in bio:

    codice:
    My name is Luis Martinez and I was born in the spring 88 to de Envigado Antioquia, from an Italian father (Sicily) and Colombian mother (Medellin). Grew up with music in their blood. The Latin American influence (approved and advocated by my father, also DEEJAY and Director of the First Latin-American music magazines in Italy "DIMENSION LATINA"), soon led me from the age of 5 years the use of passion the guitar. Thanks to the teaching of valuable Federico Poggi Pollini (KKF, Ligabue) I later formed a band with my Nicola Marino on drums, John Ruggeri bass and I on guitar and vocals. Over the years, as often happens, the new company carried me toward the rooms where electronic music is "Queen" clubs such as Kinki, Donna Rosa, Kindergarten, and the historic castle keep LINK, first as a customer and then as a simple PR, hence, prompted by my creativity and passion for music, the step between me and the console was quick ... Thus in 2005, my weapon of sound and flat, from there I began struggling with electronics, looking in my sets techno-minimal-house that "Sabor Latino" is part of my DNA. The fantasy part of me that appears in the first production, which I see so far committed to various preparations of albums, the groove already incredibly complex and mature, the fruit of my spirit "Caliente" but at the same time, with a growing commitment projected evolution of my label, which already in 2011 will be exciting to listeners enjoy going out with the participation of international DJ's and not ... Over the years, perfectly pressed, the new "breed of producer, which has developed step by step into the digital age, using software such as Reason & Ableton spontaneously, expressing ideas and emotions in every moment of my life. "My musical concept is based on a Groove DEEP / DARK atmosphere with bright and colorful .. can export itself to the upper levels of the issue, capturing the freshness and passion of the audience who listens to me, giving them a sense total wonder and novelty with great pleasure and enthusiasm on stage ... that to me. I propose that the variation of music tech house, leaving room for creativity in my mind, comparing them with listening to various artists, studying with each other in the development of various musical groove ...
    ho provato a fare:
    Codice PHP:
    $bio=mysql_real_escape_string($_POST['bio']); 
    ma mi dà sempre errore.
    Con i sogni possiamo conoscere il futuro...

  4. #4
    Utente di HTML.it
    Registrato dal
    May 2011
    Messaggi
    762
    Prova a fare trasformare la variabile con htmlentities così:

    Codice PHP:
    <?php

    $bio 
    htmlentities($bio,ENT_QUOTES,"UTF-8");

    ?>

    E puoi anche rimuovere l'in/out della variabile..tanto stai usando le virgolette doppie per la stringa della query e quindi le variabili vengono riconosciute automaticamente come tali. Ma bada bene a non avere tipo accenti o robe simili nelle altre variabili. In tal caso fai lo stesso trattamento.

    Fammi sapere.

  5. #5
    Utente di HTML.it L'avatar di gaten
    Registrato dal
    Jul 2007
    Messaggi
    1,269
    Niente da fare sempre questo errore:

    codice:
    errore query: 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 's and not ... Over the years, perfectly pressed, the new "breed of producer, whi' at line 1
    Con i sogni possiamo conoscere il futuro...

  6. #6
    Utente di HTML.it
    Registrato dal
    May 2011
    Messaggi
    762
    Appunto.. "near 's and not" . Come pensavo quindi c'è la virgoletta che dà fastidio.

    Hai fatto come ti dicevo???

    Oh al massimo usa un str_replace per la virgoletta singola e piazzaci il relativo valore..oppure meglio usa & r s q u o ; (senza spazi)..

  7. #7
    Utente di HTML.it L'avatar di gaten
    Registrato dal
    Jul 2007
    Messaggi
    1,269
    Per ora ho usato:
    Codice PHP:
    $bio htmlentities($bio,ENT_QUOTES,"UTF-8"); 
    e non va! cosa dovrei usare?
    Con i sogni possiamo conoscere il futuro...

  8. #8
    Utente di HTML.it
    Registrato dal
    May 2011
    Messaggi
    762
    Il tipo di virgoletta che ti ho consigliato al posto della virgoletta che si usa per racchiudere i valori in una query.

    Con quella non avrai problemi.

  9. #9
    Utente di HTML.it L'avatar di gaten
    Registrato dal
    Jul 2007
    Messaggi
    1,269
    Quindi avrò una cosa del tipo

    Codice PHP:
    $query "INSERT INTO muzik (name, facebook, myspace, advisor, website, image, soundcloud, bio, type)
              VALUES ('
    $name', '$facebook', '$myspace', '$advisor', '$website', '".$image."', '$soundcloud', &rsquo;$bio&rsquo;, '$type')"
    ??
    Con i sogni possiamo conoscere il futuro...

  10. #10
    Utente di HTML.it
    Registrato dal
    May 2011
    Messaggi
    762
    No

    I caratteri che ti ho suggerito devono sostituire i caratteri ALL'INTERNO delle stringhe che sono contenute nelle tue variabili...quindi NO, non avrai una roba di quel tipo...non esiste!

    Presta attenzione agli errori che ti si presentano e leggili. MySQL ti dice che c'è un errore di SINTAX...NEAR (vicino)..bla bla. Quindi a partire da lì si verifica l'errore. Quindi è lì che devi sostituire il carattere (e quelli che verranno).


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 © 2024 vBulletin Solutions, Inc. All rights reserved.