Htmlspeacialchars

Started on the old forum in August 2008 · view the original in the archive · old links redirect here

7 replies · 882 views · started 18 years ago · 1 min read

2 participants
synergyx Developer · 100 posts #1

hey guys, im sitting with a prob. everytime a member adds text with the & symbol, and displays the text he has added, an error occurs. what is the problem

synergyx Developer · 100 posts #2

is there a security Vulnerability if i add the following code at the top of my script

$txt = $_POST["txt"];
$txt = str_replace('&', "&", $txt);
$txt1 = htmlspecialchars($txt);
$result = mysql_query("INSERT INTO text_table SET message='".$txt1."'");
synergyx Developer · 100 posts #4

but what will happen if i use your code. its the same as mine

synergyx Developer · 100 posts #6

where would i place this code? must i place it where ever text is entered and sent to db

synergyx Developer · 100 posts #7

i need someone to help me understand htmlspecialchars:

correct me if im wrong.... example i add an address http://domain.com/ref=2&id=1 in a submit form (datatosend.php), the address is then posted to (procdata.php) where the page looks like this

else if($action=="addaddy")
        {
        $addy = mysql_real_escape_string($_POST["addy"]);
        $addy= str_replace('&', "&", $addy);
        {
         echo head($thm);
         echo pc();
         $addy1 = htmlspecialchars($addy);
         $result = mysql_query("INSERT INTO address SET addy='".$addy1."'");
    
         if($result)
                   {
                   echo "Address Added Successfully";
                   }
                        
         else
                  {
                   echo "Database Error!
";
                   echo "Please contact the administrator";
                   }
         }
echo homelink($ses);
echo pe();
echo foot();
         }

http://domain.com/ref=2&id=1 is posted to this form and string & is then replaced by & and then what happens at htmlspecialchars function. as far as i know after it has passed all functions it is then sent to the db

synergyx Developer · 100 posts #8

why not just use the string replace function: txt = hello & goodbye

$txt = str_replace("&","&",$txt);

then call from db

echo "$txt";

and the following is displayed: hello & goodbye.

Sign in to reply.

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close