Jump to content

Building a query error...


iPixel

Recommended Posts

Here's my build a querty code...

$sql = "UPDATE $tablename SET 
					DIST_PART_NUM = '$dist_part_num',
					DIST_PUB = '$dist_pub',
					MFR_PART_NUM = '$mfr_part_num',
					MFR_PUB = '$mfr_pub',
					ITEM_DESC = '$item_desc',
					ITEM_STD_DESC = '$item_std_desc',
					ITEM_COPY = '$item_copy',
					COST = '$cost',
					GP_MULT = '$gp_mult',
					ITEM_IMAGE = '$item_image',
					ITEM_URL = '$item_url',
					COUNTRY_OF_ORIG = '$country_of_orig',
					CATEGORY_ID = '$category_id',
					PICGROUP_KEY = '$picgroup_key',
					UPC_CODE = '$upc_code',
					LEADTIME = '$leadtime',
					UNITS = '$units',
					LENGTH = '$length',
					WIDTH = '$width',
					HEIGHT = '$height',
					WEIGHT = '$weight',
					FLAG_HAZARDOUS = '$flag_haz',
					FLAG_LTL = '$flag_ltl',
					FLAG_NON_RETURNABLE = '$flag_non',
					CAMPAIGN_KEY = '$campaign_key', ";
			foreach($atr as $key => $value)
				{
					$sql .= $value . "='" . addslashes($_POST[$value]) . "',";
				}

			$sql2 = rtrim($sql,",");

			$sql2 .= " WHERE DIST_PART_NUM = '$partnumber' OR MFR_PART_NUM = '$partnumber'";

 

Now the query get's built 100% fine that's not the issue... my issue is that sine if the table fields are named something like #_of_shelves... and the # sign causes a MySQL error...

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 26

 

How can i allow for the # sign, or any other character that can cause issues like () . , * ~ etc....

 

i tried encompassing the field name with single quotes 'fieldname' and with those slanted ones `tablename` but that did not help.

 

Any ideas?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/229301-building-a-query-error/
Share on other sites

"those slanted ones" are called backticks, and allow you to use reserved words as table/field names without MySQL getting all upset with you.  I have never tried to make a field name with any of those characters in it - and to be honest, I can't think why you would even want to (but then I can't think why you would want to cram what is clearly at least four tables worth of information into one either). I would recomend that you just don't do it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.