iPixel Posted March 2, 2011 Share Posted March 2, 2011 So i have a basic form that does a pure and simple data entry via MySQL / PHP. However the content being passed through the form is being pasted in from random sources such as PDF, Word Doc, etc... Here's an issue im noticing and do not know how to fix. If someone pastes a paragraph that has a single quote in it, that single quote >> ' << will be replaced in the database with something like so >> ’ << so a word like world's will turn into world’s. Does anyone know if there's a way to fix this issue? Thanks! Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 2, 2011 Share Posted March 2, 2011 Please show your code for processing and inserting the text into the database and the code for selecting the text from the DB and outputting to the browser. Also, what collation are you using for the database field? Quote Link to comment Share on other sites More sharing options...
iPixel Posted March 2, 2011 Author Share Posted March 2, 2011 THE FIELD WITH THE SINGLE QUOTE POSSIBILITIES <?php $item_copy = addslashes($_POST['ITEM_COPY']); ?> INSERT: <?php $sql = "INSERT INTO $tablename (DIST_PART_NUM,DIST_PUB,MFR_PART_NUM,MFR_PUB,ITEM_DESC,ITEM_STD_DESC,ITEM_COPY,COST,GP_MULT,ITEM_IMAGE,ITEM_URL,COUNTRY_OF_ORIG,CATEGORY_ID,PICGROUP_KEY,UPC_CODE,LEADTIME,UNITS,LENGTH,WIDTH,HEIGHT,WEIGHT,FLAG_HAZARDOUS,FLAG_LTL,FLAG_NON_RETURNABLE,CAMPAIGN_KEY) VALUES('$dist_part_num','$dist_pub','$mfr_part_num','$mfr_pub','$item_desc','$item_std_desc','$item_copy','$cost','$gp_mult','$item_image','$item_url','$country_of_orig','$category_id','$picgroup_key','$upc_code','$leadtime','$units','$length','$width','$height','$weight','$flag_haz','$flag_ltl','$flag_non','$campaign_key')"; $qry = mysql_query($sql) or die(mysql_error()); ?> SELECT: <?php if($dist_part_num != '') { $dist = "DIST_PART_NUM = '$dist_part_num'"; } if($mfr_part_num != '') { $mfr = "AND MFR_PART_NUM = '$mfr_part_num'"; } $sql = "SELECT * FROM $tablename WHERE $dist $mfr"; $qry = mysql_query($sql) or die(mysql_error()); $res = mysql_fetch_assoc($qry); ?> Quote Link to comment Share on other sites More sharing options...
RopeADope Posted March 2, 2011 Share Posted March 2, 2011 If you're copying and pasting, its probably a text encoding issue. I've had the same problem before. There really isn't an easy way (that I know of) to fix it. You just have to delete the problematic characters then retype them with your keyboard. Quote Link to comment Share on other sites More sharing options...
iPixel Posted March 2, 2011 Author Share Posted March 2, 2011 Yea that's what i was afraid of, i just figured maybe there was some crazy regex type coding to fix the issue. Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 2, 2011 Share Posted March 2, 2011 Well, for starters, I would suggest you use mysql_real_escape_string() instead of addslashes() Again, what is the collation for the DB field? You should also set the HTML output for UTF-8 encoding. I forget the manner in which to do this, but you can google for solutions. 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.