Jump to content

Data issues when pasting content into fields..


iPixel

Recommended Posts

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!

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.