Hardwarez Posted November 9, 2007 Share Posted November 9, 2007 I have used mysql_real_escape_string() on all data that is input and stored in my db. I am using this; in a edit form. <input type="text" size="25" MAXLENGTH="100" name="client'.$i.'" value="'; $client=$row['client']; $client=stripslashes($client); echo $client . '"' . $j . '> Stripslashes() seems to not work. The out put goes to the first \ and stops; showing the first back slash. Ie If the client name is Mr "Big". Then the output is Mr \ Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted November 9, 2007 Share Posted November 9, 2007 try this function <?php function no_slashes($array) { foreach($array as $key=>$value) { if(is_array($value)) { $value=no_slashes($value); $array_temp[$key]=$value; } else { $array_temp[$key]=stripslashes($value); } } return $array_temp; } ?> Quote Link to comment Share on other sites More sharing options...
Hardwarez Posted November 9, 2007 Author Share Posted November 9, 2007 That did not work. It only output <br /> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 9, 2007 Share Posted November 9, 2007 When formatting text containing quotes to go to the browser, you have to use the htmlentities() function: <?php echo '<input type="text" size="25" MAXLENGTH="100" name="client'.$i.'" value="' . htmlentities($row['client'], ENT_QUOTES) .'"' . $j . '>'; ?> Ken Quote Link to comment Share on other sites More sharing options...
Hardwarez Posted November 9, 2007 Author Share Posted November 9, 2007 Wow, ok, I dont understand why thats needed, but hey it works now.. Thanks! Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted November 9, 2007 Share Posted November 9, 2007 The reason why its needed: You enclose the value of your text box in double quotes, yet your value contains a double quote. So, the browser gets confused. Is it the value supposed to terminate with the first double quote it comes across? That is what it does - it doesn't 'nest' the double quotes - afterall, what would happen if the value contained a single double quote. Therefore, we use the html character codes for the quotes inside things like values of elements. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.