TechMistress Posted January 31, 2010 Share Posted January 31, 2010 Ok, I'm putting in or leaving out a , or a ; or something... Can someone help? Original code, gives me error about having an apostrophe in a couple of fields: $q1 = "insert into listings set ShortDesc ='$_POST[shortDesc]', DetailedDesc = '$_POST[DetailedDesc]', Price = '$_POST[Price]', currencyID = '$_POST[currencyID]', neighbourhood = '$_POST[neighbourhood]', PropertyType = '$_POST[PropertyType]', rooms = '$_POST[rooms]', bathrooms = '$_POST[bathrooms]', fireplace = '$_POST[fireplace]', garage = '$_POST[garage]', SquareFeet = '$_POST[squareFeet]', LotSize = '$_POST[LotSize]', HomeAge = '$_POST[HomeAge]', NearSchool = '$_POST[NearSchool]', NearTransit = '$_POST[NearTransit]', NearPark = '$_POST[NearPark]', OceanView = '$_POST[OceanView]', LakeView = '$_POST[LakeView]', MountainView = '$_POST[MountainView]', OceanWaterfront = '$_POST[OceanWaterfront]', LakeWaterfront = '$_POST[LakeWaterfront]', RiverWaterfront = '$_POST[RiverWaterfront]', image = '$ImageStr', DateAdded = '$t' "; mysql_query($q1) or die(mysql_error()); So, I added the mysql_real_escape_string on the two fields in question: ShortDesc = mysql_real_escape_string($_POST[shortDesc]), DetailedDesc = mysql_real_escape_string($_POST[DetailedDesc]), Price = '$_POST[Price]', currencyID = '$_POST[currencyID]', neighbourhood = '$_POST[neighbourhood]', PropertyType = '$_POST[PropertyType]', rooms = '$_POST[rooms]', bathrooms = '$_POST[bathrooms]', fireplace = '$_POST[fireplace]', garage = '$_POST[garage]', SquareFeet = '$_POST[squareFeet]', LotSize = '$_POST[LotSize]', HomeAge = '$_POST[HomeAge]', NearSchool = '$_POST[NearSchool]', NearTransit = '$_POST[NearTransit]', NearPark = '$_POST[NearPark]', OceanView = '$_POST[OceanView]', LakeView = '$_POST[LakeView]', MountainView = '$_POST[MountainView]', OceanWaterfront = '$_POST[OceanWaterfront]', LakeWaterfront = '$_POST[LakeWaterfront]', RiverWaterfront = '$_POST[RiverWaterfront]', image = '$ImageStr', DateAdded = '$t' "; but, this is breaks the post also. I get this 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 '1235000', currencyID = '1', neighbourhood = '', PropertyType = 'W' at line 14 So now it's allowing the apostrophe, but it messed up the set. How do I use the escape portion, without breaking the set? I've tried so many ways, but it always breaks somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/190419-insert-into-set-syntax-help/ Share on other sites More sharing options...
TechMistress Posted January 31, 2010 Author Share Posted January 31, 2010 Solved: ShortDesc = '".mysql_real_escape_string($_POST[shortDesc])."', DetailedDesc = '".mysql_real_escape_string($_POST[DetailedDesc])."', Quote Link to comment https://forums.phpfreaks.com/topic/190419-insert-into-set-syntax-help/#findComment-1004486 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.