This MYSQL INSERT code breaks on new server - mysql

I had a small app on Hostgator shared hosting and the below code worked fine and inserted fields. Now I get a a mysql error because the insert returns false. Im thinking maybe the new server which uses MYSQL 5.6.35, has some new insert syntax that is now making my old syntax incorrect. Can someone who knows and have been following the MYSQL changes please look at the code below and see what is no longer allowed or deprecated.
$insertsql = "INSERT INTO members ( lastname, firstname,
member_dob_month, member_dob_year, spouseslastname,
spousesfirstname, spouse_dob_month, spouse_dob_year, address, city,
state, zip, phone, phone2, phone3,
memberemail, email2, email3, boatname, boatmake,
propulsion, boatyear, boatlength, slipno, fueltype,
dinghies, ebeacon, beam, draft, yacht_haven,
registration_no, registration_exp_date, insurance_co, policy_no,
policy_exp_date, coowned, coowner, talents, volunteer, profiled,
electrical, boatname2, boatmake2, propulsion2, boatyear2,
boatlength2, slipno2, fueltype2, beam2, draft2, registration_no2,
registration_exp_date2, insurance_co2, policy_no2, policy_exp_date2,
coowned2, coowner2, electrical2, boatname3, boatmake3,
propulsion3, boatyear3,boatlength3, slipno3, fueltype3,
beam3, draft3, registration_no3, registration_exp_date3,insurance_co3,
policy_no3, policy_exp_date3, coowned3, coowner3, electrical3, active
) VALUES ( '$lastname', '$firstname','$member_dob_month',
'$member_dob_year',
'$spouseslastname','$spousesfirstname', '$spouse_dob_month',
'$spouse_dob_year', '$address1', '$city','$state', '$zip', '$phone',
'$phone2', '$phone3','$email', '$email2', '$email3', '$boatname',
'$boatmake','$propulsion', '$boatyear', '$boatlength', '$slipno',
'$fueltype','$dinghies', '$ebeacon', '$beam', '$draft',
'$yacht_haven','$registration_no', '$registration_exp_date',
'$insurance_co', '$policy_no', '$policy_exp_date','$coowned',
'$coowner', '$talents', '$volunteer',
'$profiled','$electrical', '$boatname2', '$boatmake2', '$propulsion2',
'$boatyear2','$boatlength2', '$slipno2', '$fueltype2', '$beam2',
'$draft2','$registration_no2',
'$registration_exp_date2', '$insurance_co2', '$policy_no2',
'$policy_exp_date2','$coowned2', '$coowner2', '$electrical2',
'$boatname3', '$boatmake3','$propulsion3',
'$boatyear3', '$boatlength3', '$slipno3', '$fueltype3', '$beam3',
'$draft3', '$registration_no3',
'$registration_exp_date3','$insurance_co3', '$policy_no3',
'$policy_exp_date3', '$coowned3', '$coowner3', '$electrical3',
$active)";
/* Prepare statement */
$stmt = $c1->query($insertsql);
if ($stmt === false) {
trigger_error('Wrong SQL: ' . $insertsql . ' Error: ' . $c1->error,
E_USER_ERROR);
}
Here is the SQL error shown on screen:
Fatal error: Wrong SQL: INSERT INTO members ( lastname, firstname,
member_dob_month, member_dob_year, spouseslastname, spousesfirstname,
spouse_dob_month, spouse_dob_year, address1, city, state, zip, phone,
phone2, phone3, memberemail, email2, email3, boatname, boatmake,
propulsion, boatyear, boatlength, slipno, fueltype, dinghies, ebeacon,
beam, draft, yacht_haven, registration_no, registration_exp_date,
insurance_co, policy_no, policy_exp_date, coowned, coowner, talents,
volunteer, profiled, electrical, boatname2, boatmake2, propulsion2,
boatyear2, boatlength2, slipno2, fueltype2, beam2, draft2,
registration_no2, registration_exp_date2, insurance_co2, policy_no2,
policy_exp_date2, coowned2, coowner2, electrical2, boatname3,
boatmake3, propulsion3, boatyear3,boatlength3, slipno3, fueltype3,
beam3, draft3, registration_no3, registration_exp_date3,insurance_co3,
policy_no3, policy_exp_date3, coowned3, coowner3, electrical3, active
) VALUES ( 'testerr', 'testing','99', '99', '','', '99', '99', '', '',
in /home/6/public_html/add.php
on line 129
UPDATE: I echoed the SQL and used it in PhpMyadmin to run as SQL to find errors and I found that its identifying all fields without default values as ERRORS. Likely cause new server has STRICT_TRANS_TABLES enabled. Will see if I can get the host to disable for me or I will make each field default value NULL.

Related

Error in MySQL Syntax run on remote server using PyCharm

I am fairly new to programming and I've been trying to implement this code in Python, using PyCharm. I'm running the code via a remote server, using PyCharm on my local computer. It was written by a former colleague, and has been giving a lot of encoding issues since we updated the packages like MySQL and the Python interpreter to 3.8. The MySQL version is 8.0, but this is an update. That was not the version installed originally when the code was written.
This is the full error that I am getting:
findBestMatch
*** WARNING: FoundCity[i] = {'Country': 'Austria', 'Page': 'Contact', 'Confidence': 10, 'Mentions': 1}
WriteToDB
Problem <class 'MySQLdb._exceptions.ProgrammingError'>
Traceback (most recent call last):
File "/remotepath/TextMining/NER/FindLocationStoreSQL.py", line 399, in
WriteToDB(c.title(), cn, idProject, 10, "Contact", "v1", cursor, db, database_country)
File "/remotepath/TextMining/NER/FindLocationStoreSQL.py", line 286, in WriteToDB
cursor.execute(sql,values)
File "/home/localhost/.local/lib/python3.8/site-packages/MySQLdb/cursors.py", line 206, in execute
res = self._query(query)
File "/home/localhost/.local/lib/python3.8/site-packages/MySQLdb/cursors.py", line 319, in _query
db.query(q)
File "/home/localhost/.local/lib/python3.8/site-packages/MySQLdb/connections.py", line 259, in query
_mysql.connection.query(self, query)
MySQLdb._exceptions.ProgrammingError: (1064, "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 'City text mined, Country from datasource'',Confidence='10',FoundWhere=''Contact'' at line 1")
Process finished with exit code -1
The code sample of the function it is trying to run is below:
def findBestMatch(FoundCity,FoundCountry,database_country):
pair_candidates = []
for i in range(0,5):
for j in range(0,5):
if len(FoundCity)>i and len(FoundCountry)>j:
city_i = FoundCity[i].get('City')
country_j = FoundCountry[j].get('Country')
if city_i != None and country_j != None:
#sql = "SELECT City,Country_CountryName,Longitude,Latitude FROM Semanticon.City where city like '{0}' and Country_CountryName like '{1}' and Population>0 order by Population desc".format(FoundCity[i]['City'].encode('utf-8'),FoundCountry[j]['Country'].encode('utf-8'))
sql = "SELECT City,Country_CountryName,Longitude,Latitude FROM Semanticon.City where city like '{0}' and Country_CountryName like '{1}' and Population>0 order by Population desc".format(
FoundCity[i]['City'], FoundCountry[j]['Country'])
try:
cursor.execute(sql)
except:
db = MySQLdb.connect(host, username, password, database, charset='utf8')
db.set_character_set("utf8")
cursor = db.cursor()
cursor.execute(sql)
resul = cursor.fetchall()
if len(resul)>0:
pair_candidates.append({"City":FoundCity[i]['City'],"Country":FoundCountry[j]['Country'],"Score":(FoundCity[i]["Confidence"]+FoundCountry[j]["Confidence"]+0.5*(FoundCity[i]["Mentions"]+FoundCountry[j]["Mentions"]))})
#return FoundCity[i]['City'],FoundCountry[j]['Country'],FoundCity[i]['Confidence']
else:
if city_i == None:
print("*** WARNING: FoundCity[i] = ", FoundCity[i])
else:
print("*** WARNING: FoundCountry[j] = ", FoundCountry[j])
I had to take the encoding out, hence the commented out 'sql' line. The encoding was causing problems and adding an extra 'b' to the string to be read from the database.
The 'WriteToDB' function that it's complaining about is below:
def WriteToDB(City,Country,ProjectId,Confidence,Location,Version,cursor,db,database_country):
sql = None
if database_country!="":
if database_country == Country:
if City != "":
#sql = "UPDATE ProjectLocation SET City='{0}',DataTrace='{1}',Confidence={2},FoundWhere='{3}' WHERE Projects_idProjects={4} and Country='{5}';".format(City," City text mined, Country from datasource",Confidence,Location,ProjectId,original_database_cntry)
sql = "UPDATE ProjectLocation SET City='%s',DataTrace='%s',Confidence='%s',FoundWhere='%s' WHERE Projects_idProjects='%s' and Country='%s';"
values = (City, " City text mined, Country from datasource", Confidence, Location, ProjectId,
original_database_cntry)
if database_country!=Country:
if Country.encode('utf-8') in database_country:
#sql = "UPDATE ProjectLocation SET City='{0}',DataTrace='{1}',Confidence={2},FoundWhere='{3}' WHERE Projects_idProjects={4} and Country='{5}';".format(
# City, " City text mined, Country from datasource", Confidence, Location, ProjectId,
#original_database_cntry)
sql = "UPDATE ProjectLocation SET City='%s',DataTrace='%s',Confidence='%s',FoundWhere='%s' WHERE Projects_idProjects='%s' and Country='%s';"
values = (City, " City text mined, Country from datasource", Confidence, Location, ProjectId,
original_database_cntry)
else:
print("Country conflict in project:"+str(ProjectId))
else:
#sql = "Insert into ProjectLocation (Type,City,Country,Projects_idProjects,Original_idProjects,IsLocationFromDataset,Confidence,FoundWhere,Version,DataTrace)" \
# "Values ('{0}','{1}','{2}',{3},{4},0,{5},'{6}','{7}','{8}')".format("Main",City,Country,ProjectId,ProjectId,Confidence,Location,Version,"Both minded from text v0.1")
sql = "Insert into ProjectLocation (Type,City,Country,Projects_idProjects,Original_idProjects,IsLocationFromDataset,Confidence,FoundWhere,Version,DataTrace)" \
"Values ('%s','%s','%s','%s',0,'%s','%s','%s','%s','%s')"
values = ("Main", City, Country, ProjectId,ProjectId, Confidence, Location, Version, "Both minded from text v0.1")
if sql!=None:
cursor.execute(sql,values)
db.commit()
I commented out the SQL queries as shown and tried to bind them instead, because it was giving a lot of encoding errors. I'm not sure how to get rid of this error and not end up with the encoding errors yet again.
Can someone help?
UPDATE to the question.
I reverted back all the sql queries, and used the queries with the encoding now (previously commented out) and I am getting 'b's in the output.
Any suggestions on how to properly encode these SQL queries so the binary encoding does not come out as b's in the output?
Here is a sample of the output:
ProjectID,ProjectName,FoundCity,FoundCountry,DatabaseCity,DatabaseCountry,Confidence,FoundWhere,Website
2542, Migrantour Country,,b'',b'',b'',10,Contact,link
3938,GeoSmartCity,,,b'',b'',10,Contact,link

How to make a dynamic 'CREATE TABLE' MySQL query from python list of column names and datatypes usin 'pymysql'?

I have the following data:
table_name=xyz
column_names=['c1', 'c2', 'c3', 'c4']
column_datatypes=['VARCHAR(40)', 'BIGINT(40)', 'BIGINT(20)', 'VARCHAR(10)']
Which I am reading from a file .i.e The length of the above lists can vary.So I want to create a dynamic 'CREATE TABLE' MySQL query such as:
CREATE TABLE xyz(c1 VARCHAR(40),c2 BIGINT(40),c3 BIGINT(20),c4 VARCHAR(10));
How can I forge a string query such as above(maybe using string.format())?
Also, Kindly upvote the question (If worthy) as I am on verge of getting blocked from asking further questions as my previous questions did not receive any voting.
Here you go!
import MySQLdb as mdb
table_name='xyz'
column_names=['c1', 'c2', 'c3', 'c4']
column_datatypes=['VARCHAR(40)', 'BIGINT(40)', 'BIGINT(20)', 'VARCHAR(10)']
db=mdb.connect(host='localhost',user='root',passwd='*****',db='test',port=3306)
cursor=db.cursor()
create_stement='create table '+table_name + '('
i=0
while i< len(column_names)-1 :
create_stement =create_stement +column_names[i] +' '+column_datatypes[i]+' ,'
i=i+1
create_stement =create_stement +column_names[i] +' '+column_datatypes[i]+' )'
print(create_stement)
cursor.execute(create_stement)
print('Done')

SQL % statement in python returns error

I created 5 tables in mysql workbench 5.7 in which I will pull data from APIgraph queries for a given facebook page.
However, when I run the code, it throws an error:
ProgrammingError: 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 '%s, %s)' at line 1
Here is the part of the code which I think contains the error :
#create connection to db
connection = connect_db()
cursor = connection.cursor()
#SQL request for inserting the date of the page into the database
insert_page = ("INSERT INTO page"
"(fb_id, name)"
"VALUES (%s, %s)")
insert_posts = ("INSERT INTO posts "
"(page_id, fb_post_id, message, time_created)"
"VALUES (%s, %s, %s, %s)")
And I finally put the data at the end of the code:
cursor.execute(insert_page, json_pageiddata)
Any ideas? Thanks for helping
EDIT: here is my json_pageiddtata variable, obtained from a URL query with APIgraph:
pageid_url = create_pageid_url(current_page, APP_ID, APP_SECRET)
json_pageiddata = render_to_json(pageid_url)
print json_pageiddata["name"], json_pageiddata["id"]
If you are using data as dictionary u need to specify index name, try to use %(name)s.

query exec fails when trying to write from qt to MS Sql database in windows using ODBC

I connect to my MSSQL database with odbc and writing data to it. I am not sure why I get the error:
QODBCResult::exec: unable to bind variable: “[Microsoft][ODBC SQL Server Driver]Optional feature not implemented”
bool DataManager::registerClient(Client&)
“INSERT INTO ClientMaster (first_name, mid_name, last_name, phone_number, email_id, address_line1, address_line2, address_line3, dob) VALUES (xxx, xxx , xxx, +xxx-xxx, xx, xx, x, x, 1987-08-30)”
bool DataManager::registerClient(Client&) error “[Microsoft][ODBC SQL Server Driver]Optional feature not implemented QODBC3: Unable to bind variable”
mDatabase = QSqlDatabase::addDatabase("QODBC");
mDatabase.setDatabaseName("DRIVER={SQL SERVER};SERVER=localhost;DATABASE=GLINK_CLIENT_MGMNT;");
mDatabase.setUserName("sa");
mDatabase.setPassword("123456");
if(!mDatabase.open())
is my database connection part and below is my query execution part.
QSqlQuery query(mDatabase);
query.prepare("INSERT INTO ClientMaster (first_name, mid_name, last_name, phone_number, "
"email_id, address_line1, address_line2, address_line3, dob) "
"VALUES (:first_name, :mid_name, :last_name, :phone_number, :email_id, "
":address_line1, :address_line2, :address_line3, :dob)");
QString phoneNumber = "+";
phoneNumber.append(client.phoneCode);
phoneNumber.append("-");
phoneNumber.append(client.phoneNumber);
query.bindValue(":first_name", client.firstName);
query.bindValue(":mid_name", client.midName);
query.bindValue(":last_name", client.lastName);
query.bindValue(":phone_number", phoneNumber);
query.bindValue(":email_id", client.emailId);
query.bindValue(":address_line1", client.addressLine1);
query.bindValue(":address_line2", client.addressLine2);
query.bindValue(":address_line3", client.addressLine3);
query.bindValue(":dob", client.dob);
regStatus = query.exec();
The issue got resolved. I hope the below case is the specific reason for the issue.
I gave date input in the format (yyyy-MM-dd), i.e. :
query.bindValue(":dob", client.dob.toString(yyyy-MM-dd));
I came to know that MSSQL takes date in the particular format only. I am not certain about this, however it works fine now.

Mysql Error I can't find/may not exist

$query = "
INSERT INTO rets_property_res (ACREAGE, BATHS_FULL, BATHS_HALF, BEDROOMS, CATEGORY, CITY, COUNTY, CO_LA_CODE, CO_LO_CODE, CURRENT_PRICE, DATE_MODIFIED, DIRECTIONS, ELEM_SCHOOL, FTR_APPLIANCE, FTR_CONSTRC_STATUS, FTR_CONSTRUC, FTR_COOLING, FTR_DESIGN, FTR_DININGTYPE, FTR_ENERGY, FTR_EXTERIOR, FTR_FACILITY, FTR_FLOORS, FTR_HEATING, FTR_INTERIOR, FTR_INTERNET, FTR_LOTDESC, FTR_MSTR_BATH_DESC, FTR_MSTR_BDRM_DESC, FTR_PARKING, FTR_POOL, FTR_ROOF, FTR_SIDING, FTR_SPECIAL_SALE_TYPE, FTR_STYLE, FTR_WATERFRONT, FTR_WATERVIEW, HIGH_SCHOOL, INTERMEDIATE_SCHOOL, LA_CODE, LIST_DATE, LIST_PRICE, LOT_DIMENSIONS, LO_CODE, MEDIA_FLAG, MIDDLE_SCHOOL, MLS_ACCT, PHOTO_COUNT, PHOTO_DATE_MODIFIED, PROJ_NAME, PROP_TYPE, REMARKS, STATE, STATUS, STREET_DIR, STREET_NAME, STREET_NUM, SUBDIVISION, TOT_HEAT_SQFT, UNIT_NUM, VT_YN, YEAR_BUILT, ZIP)
VALUES (\"$listing[ACREAGE]\", \"$listing[BATHS_FULL]\", \"$listing[BATHS_HALF]\", \"$listing[BEDROOMS]\", \"$listing[CATEGORY]\", \"$listing[CITY]\", \"$listing[COUNTY]\", \"$listing[CO_LA_CODE]\", \"$listing[CO_LO_CODE]\", \"$listing[CURRENT_PRICE]\", \"$listing[DATE_MODIFIED]\", \"$listing[DIRECTIONS]\", \"$listing[ELEM_SCHOOL]\", \"$listing[FTR_APPLIANCE]\", \"$listing[FTR_CONSTRC_STATUS]\", \"$listing[FTR_CONSTRUC]\", \"$listing[FTR_COOLING]\", \"$listing[FTR_DESIGN]\", \"$listing[FTR_DININGTYPE]\", \"$listing[FTR_ENERGY]\", \"$listing[FTR_EXTERIOR]\", \"$listing[FTR_FACILITY]\", \"$listing[FTR_FLOORS]\", \"$listing[FTR_HEATING]\", \"$listing[FTR_INTERIOR]\", \"$listing[FTR_INTERNET]\", \"$listing[FTR_LOTDESC]\", \"$listing[FTR_MSTR_BATH_DESC]\", \"$listing[FTR_MSTR_BDRM_DESC]\", \"$listing[FTR_PARKING]\", \"$listing[FTR_POOL]\", \"$listing[FTR_ROOF]\", \"$listing[FTR_SIDING]\", \"$listing[FTR_SPECIAL_SALE_TYPE]\", \"$listing[FTR_STYLE]\", \"$listing[FTR_WATERFRONT]\", \"$listing[FTR_WATERVIEW]\", \"$listing[HIGH_SCHOOL]\", \"$listing[INTERMEDIATE_SCHOOL]\", \"$listing[LA_CODE]\", \"$listing[LIST_DATE]\", \"$listing[LIST_PRICE]\", \"$listing[LOT_DIMENSIONS]\", \"$listing[LO_CODE]\", \"$listing[MEDIA_FLAG]\", \"$listing[MIDDLE_SCHOOL]\", \"$listing[MLS_ACCT]\", \"$listing[PHOTO_COUNT]\", \"$listing[PHOTO_DATE_MODIFIED]\", \"$listing[PROJ_NAME]\", \"$listing[PROP_TYPE]\", \"$listing[REMARKS]\", \"$listing[STATE]\", \"$listing[STATUS]\", \"$listing[STREET_DIR]\", \"$listing[STREET_NAME]\", \"$listing[STREET_NUM]\", \"$listing[SUBDIVISION]\", \"$listing[TOT_HEAT_SQFT]\", \"$listing[UNIT_NUM]\", \"$listing[VT_YN]\", \"$listing[YEAR_BUILT]\", \"$listing[ZIP]\")";
$result = mysql_query($query);
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 'television above your gas fireplace or enjoying your view of the Bay. Then open' at line 2
I can't find the error. I have been looking for like 2 hrs. What is spilled out as an "error" is from the REMARKS field. There isn't a syntax error though.
Try this:
$query = "
INSERT INTO rets_property_res (ACREAGE, BATHS_FULL, BATHS_HALF, BEDROOMS, CATEGORY, CITY, COUNTY, CO_LA_CODE, CO_LO_CODE, CURRENT_PRICE, DATE_MODIFIED, DIRECTIONS, ELEM_SCHOOL, FTR_APPLIANCE, FTR_CONSTRC_STATUS, FTR_CONSTRUC, FTR_COOLING, FTR_DESIGN, FTR_DININGTYPE, FTR_ENERGY, FTR_EXTERIOR, FTR_FACILITY, FTR_FLOORS, FTR_HEATING, FTR_INTERIOR, FTR_INTERNET, FTR_LOTDESC, FTR_MSTR_BATH_DESC, FTR_MSTR_BDRM_DESC, FTR_PARKING, FTR_POOL, FTR_ROOF, FTR_SIDING, FTR_SPECIAL_SALE_TYPE, FTR_STYLE, FTR_WATERFRONT, FTR_WATERVIEW, HIGH_SCHOOL, INTERMEDIATE_SCHOOL, LA_CODE, LIST_DATE, LIST_PRICE, LOT_DIMENSIONS, LO_CODE, MEDIA_FLAG, MIDDLE_SCHOOL, MLS_ACCT, PHOTO_COUNT, PHOTO_DATE_MODIFIED, PROJ_NAME, PROP_TYPE, REMARKS, STATE, STATUS, STREET_DIR, STREET_NAME, STREET_NUM, SUBDIVISION, TOT_HEAT_SQFT, UNIT_NUM, VT_YN, YEAR_BUILT, ZIP)
VALUES (
'".mysql_real_escape_string($listing['ACREAGE'])."',
'".mysql_real_escape_string($listing['BATHS_FULL'])."', '".mysql_real_escape_string($listing['BATHS_HALF'])."', '".mysql_real_escape_string($listing['BEDROOMS'])."', '".mysql_real_escape_string($listing['CATEGORY'])."', '".mysql_real_escape_string($listing['CITY'])."', '".mysql_real_escape_string($listing['COUNTY'])."', '".mysql_real_escape_string($listing['CO_LA_CODE'])."', '".mysql_real_escape_string($listing['CO_LO_CODE'])."', '".mysql_real_escape_string($listing['CURRENT_PRICE'])."', '".mysql_real_escape_string($listing['DATE_MODIFIED'])."', '".mysql_real_escape_string($listing['DIRECTIONS'])."', '".mysql_real_escape_string($listing['ELEM_SCHOOL'])."', '".mysql_real_escape_string($listing['FTR_APPLIANCE'])."', '".mysql_real_escape_string($listing['FTR_CONSTRC_STATUS'])."', '".mysql_real_escape_string($listing['FTR_CONSTRUC'])."', '".mysql_real_escape_string($listing['FTR_COOLING'])."', '".mysql_real_escape_string($listing['FTR_DESIGN'])."', '".mysql_real_escape_string($listing['FTR_DININGTYPE'])."', '".mysql_real_escape_string($listing['FTR_ENERGY'])."', '".mysql_real_escape_string($listing['FTR_EXTERIOR'])."', '".mysql_real_escape_string($listing['FTR_FACILITY'])."', '".mysql_real_escape_string($listing['FTR_FLOORS'])."', '".mysql_real_escape_string($listing['FTR_HEATING'])."', '".mysql_real_escape_string($listing['FTR_INTERIOR'])."', '".mysql_real_escape_string($listing['FTR_INTERNET'])."', '".mysql_real_escape_string($listing['FTR_LOTDESC'])."', '".mysql_real_escape_string($listing['FTR_MSTR_BATH_DESC'])."', '".mysql_real_escape_string($listing['FTR_MSTR_BDRM_DESC'])."', '".mysql_real_escape_string($listing['FTR_PARKING'])."', '".mysql_real_escape_string($listing['FTR_POOL'])."', '".mysql_real_escape_string($listing['FTR_ROOF'])."', '".mysql_real_escape_string($listing['FTR_SIDING'])."', '".mysql_real_escape_string($listing['FTR_SPECIAL_SALE_TYPE'])."', '".mysql_real_escape_string($listing['FTR_STYLE'])."', '".mysql_real_escape_string($listing['FTR_WATERFRONT'])."', '".mysql_real_escape_string($listing['FTR_WATERVIEW'])."', '".mysql_real_escape_string($listing['HIGH_SCHOOL'])."', '".mysql_real_escape_string($listing['INTERMEDIATE_SCHOOL'])."', '".mysql_real_escape_string($listing['LA_CODE'])."', '".mysql_real_escape_string($listing['LIST_DATE'])."', '".mysql_real_escape_string($listing['LIST_PRICE'])."', '".mysql_real_escape_string($listing['LOT_DIMENSIONS'])."', '".mysql_real_escape_string($listing['LO_CODE'])."', '".mysql_real_escape_string($listing['MEDIA_FLAG'])."', '".mysql_real_escape_string($listing['MIDDLE_SCHOOL'])."', '".mysql_real_escape_string($listing['MLS_ACCT'])."', '".mysql_real_escape_string($listing['PHOTO_COUNT'])."', '".mysql_real_escape_string($listing['PHOTO_DATE_MODIFIED'])."', '".mysql_real_escape_string($listing['PROJ_NAME'])."', '".mysql_real_escape_string($listing['PROP_TYPE'])."', '".mysql_real_escape_string($listing['REMARKS'])."', '".mysql_real_escape_string($listing['STATE'])."', '".mysql_real_escape_string($listing['STATUS'])."', '".mysql_real_escape_string($listing['STREET_DIR'])."', '".mysql_real_escape_string($listing['STREET_NAME'])."', '".mysql_real_escape_string($listing['STREET_NUM'])."', '".mysql_real_escape_string($listing['SUBDIVISION'])."', '".mysql_real_escape_string($listing['TOT_HEAT_SQFT'])."', '".mysql_real_escape_string($listing['UNIT_NUM'])."', '".mysql_real_escape_string($listing['VT_YN'])."', '".mysql_real_escape_string($listing['YEAR_BUILT'])."', '".mysql_real_escape_string($listing['ZIP'])."')";
$result = mysql_query($query);
Note that this is not the best way to do it and you should use MySQLi/PDO for a more secure solution.
To be honest.. it is very hard to debug like this. There could be a chance that in REMARKS field, you have un-escaped double quote or other characters that break the query compiling. Have you tried to insert a small amount of data first?
I will suggest inserting a 'hello world' first before going crazy with this kind of insert.
I also suggest using single quote like '$listing[REMARKS]' as the default mysql syntax.