php - Where can I place addslashes coding that will allow "/',. (punctuation) to show up on the webpage -


where can place addslashes or magicquotes coding allow punctuation show when users submit data website name , city fields?

if(isset($_post['submit'])) {    $name=$_post["element_1"]; $xxx=$_post["element_2_1"]; $xxxxx=$_post["element_2_2"]; $xxxxx=$_post["element_2_3"]; $xxxxx=$_post["element_3_1"]; $xxxxxd=$_post["element_3_2"]; $xxxxxx=$_post["element_3_3"]; $xxxxx=$_post["element_4_1"]; $xxxxx=$_post["element_4_2"]; $city=$_post["element_4_3"]; $xxx=$_post["element_4_4"]; $xxp=$_post["element_4_5"]; $desc=$_post["element_5"]; //$file=$_files['element_6']; $link=$_post["element_7"]; $stdate=$stdatemm."-".$stdatedd."-".$stdateyy; $endate=$endatemm."-".$endatedd."-".$endateyy; $user=$_post["postuser"]; 

you need escape user-submitted content while saving database.

// var `"/'` chars $name=$_post["element_1"];  // escape database storage $name_escaped = mysql_real_escape_string($name);  // use escaped version in query mysql_query("insert table (column) values ('" . $name_escaped . "')"); 

note: mysql_real_escape_string() function must called after have init mysql connection, before execute mysql query.

note: way of executing mysql queries deprecated of php 5.5, therefore should use mysqli or pdo methods.

in case, when retrieving content database shouldn't escaped, therefor if want display on html page make sure use htmlspecialchars() chars "<" don't break html:

<html> <body>     <div>         <?php echo htmlspecialchars($name_fromdb); ?>     </div> </body> </html> 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -