PHP - apostrophe problem in my form field - Asked By Olusegun A. on 14-Oct-10 06:40 AM

am having problem with my apostrophe sign (') in my form field. whenever an apostrophe is inserted in my form (eg can't, don't etc) it will be sent or echoed or store in my database as can/'t or don/'t. what can i do to make it appear the normal way?


_ash_ k replied to Olusegun A. on 14-Oct-10 07:57 AM
Use the addslashes() function to remove slashes from the final query. 
pradeep joshi replied to Olusegun A. on 10-Jan-11 03:59 AM

   Hi,here is a complete code in php which you can try

   html form part

   <form method="post">
   <input type="text" name="test"  />
   <input type="submit" name="submit" value="ok" />

   php script to insert value in data


$link = mysql_connect("host","username","passord");

      echo $var;      //here is the form variable which user enter in the form contain apostrophe
      echo "<br><br>";
      echo "don't";   //here is test for echoing the variable that contain apostrophe
      echo "<br>";
      $query1="insert into table_name(column_name)values(\"$var\")";   //variable to store in the database
        echo "inserted";
        echo "not inserted";


     when you run tihs code enter table name in the place of table_name and column name in the place of column_name and run the query.
     it will print same as you have entered in the form field.
    I think this will help you.