Jump to content

Insert into SET syntax help


TechMistress

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/190419-insert-into-set-syntax-help/
Share on other sites

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.