hi again, im goin crazy with a simple things. i have a form in a file, with the value in a echo ""; <option value=valle d'aosta>Val D'Aosta</option> PHP: as you can see it has a space, then a letter and an apostroph, i tried with ' ' to escape the apostroph, but the query insert \''' so the excape is \? but if i write \' , the query print \\' (lol), btw the big problem is that the query doesnt insert the space, example valle d'aosta, inserts only 'valle'. i tried also $regione=mysql_escape_string($_REQUEST['regione']); where 'regione' is the name of the form, a <select>. any suggestion? thx in advance
you either need to add the \ to escape the ' or you can use the magic_quote function to assist you. Google: magic_quotes to help you out. Let me know if you need some more help!
thx for the answer,i tried putting \' but it prints \\' so t wont work in my case, and i know the magic quote, but i cant access the php.ini cause the server isnt mine, but im hosted i can avoid that with stripslashes, so the apostrph problem is resolved, but how can i add a space? and if the problem is in the type in the databasE? im using varchar...it could be trim the space?
i resolved with <option value=\"valle d'aosta\">Val D'Aosta</option> PHP: the output was "valle d\'aosta", but i used stripslashes($valle) and thats ok now
To work with data here's the trick: when putting data out to the web, get rid of ' and " by converting them to html characters: $textOut=html_entities($textIn,ENT_QUOTES,'UTF-8'); Code (markup): for reading in, you'll need to check magic quotes using the get_magic_quotes_gpc() function, and only remove then: // $textin is your data from the form if (get_magic_quotes_gpc()) $textin=stripslashes($textin); Code (markup): and finally, for db, you use the mysql_escape_string() before writing it to the db: $textForDb=mysql_escape_string($text); Code (markup): the will make the data safe for db (including single quotes).
as i said, i resolved with: in the form value: <option value=\"valle d'aosta\">Val D'Aosta</option> and then i stripslashes the value to remove the "\"