$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.
Related
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.
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.
this is my query:
update `zen_meta_tags_products_description`
set `metatags_keywords`= 'ice machine, ice maker, ice flaker, Brema,'
WHERE `products_id` = ('1231'; '1232'; '1233'; '1234'; '1235'; '1236'; '1237'; '1238'; '1239'; '1240';)
Error
MySQL said: Documentation
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 '1232, 1233' at line 1
You cannot use = to compare multiple values. You need to use IN(). The separator for values in IN() is a comma, not a semi colon. The last one is also not necessary and will cause an error. The quotes around the IDs are also not necessary unless you actually did store them as strings.
update zen_meta_tags_products_description
set metatags_keywords= 'ice machine, ice maker, ice flaker, Brema,'
WHERE products_id IN(1231, 1232, 1233, 1234, 1235, 1236, 1237, 1238, 1239, 1240)
Remove semicolom from your list
Insted of = use IN to get write result:
UPDATE `zen_meta_tags_products_description`
set `metatags_keywords`= 'ice machine, ice maker, ice flaker, Brema,'
WHERE `products_id` IN ('1231', '1232', '1233','1234', '1235', '1236', '1237', '1238', '1239', '1240') ;
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.
INSERT INTO jos_race_calendrier_regional (id, evt_code, evt_date_comp, evt_station, evt_activite, evt_comite, evt_club_num, evt_club_nom, evt_nom, evt_dt, org_nom, org_adresse, org_adresse2, org_adresse3, org_ville, org_site, cont_nom, cont_tel, cont_gsm, cont_fax, cont_mail, epr_codex, epr_date, epr_sexe, epr_regroupement, epr_grille_categorie, epr_categorie, epr_discipline, epr_distance, epr_homologation') VALUES ( '79', 'evt_code', 'evt_date_comp', 'evt_station', 'evt_activite', 'evt_comite', 'evt_club_num', 'evt_club_nom', 'evt_nom', 'evt_dt', 'org_nom', 'org_adresse1', 'org_adresse2', 'org_adresse3', 'org_ville', 'org_site', 'cont_nom', 'cont_tel', 'cont_gsm', 'cont_fax', 'cont_mail', 'epr_codex', 'epr_date', 'epr_sexe', 'epr_regroupement', 'epr_grille_categorie', 'epr_categorie', 'epr_discipline', 'epr_distance_style', 'epr_homologation')
i am getting following error
#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 '') VALUES ( '79', 'evt_code', 'evt_date_comp', 'evt_station', 'evt_activite', 'e' at line 1
The error message has already told you where your syntax error is (near), so you should look at your code again to find out what's wrong yourself, but I'll just pinpoint it to the very character for you now.
You have a misplaced single quote here:
epr_homologation') VALUES
Should be
epr_homologation) VALUES
Extra quote after epr_homologation:
INSERT INTO jos_race_calendrier_regional (id, evt_code, evt_date_comp, evt_station, evt_activite, evt_comite, evt_club_num, evt_club_nom, evt_nom, evt_dt, org_nom, org_adresse, org_adresse2, org_adresse3, org_ville, org_site, cont_nom, cont_tel, cont_gsm, cont_fax, cont_mail, epr_codex, epr_date, epr_sexe, epr_regroupement, epr_grille_categorie, epr_categorie, epr_discipline, epr_distance, epr_homologation) VALUES ( '79', 'evt_code', 'evt_date_comp', 'evt_station', 'evt_activite', 'evt_comite', 'evt_club_num', 'evt_club_nom', 'evt_nom', 'evt_dt', 'org_nom', 'org_adresse1', 'org_adresse2', 'org_adresse3', 'org_ville', 'org_site', 'cont_nom', 'cont_tel', 'cont_gsm', 'cont_fax', 'cont_mail', 'epr_codex', 'epr_date', 'epr_sexe', 'epr_regroupement', 'epr_grille_categorie', 'epr_categorie', 'epr_discipline', 'epr_distance_style', 'epr_homologation')
Also, if 'id' is an int, you don't put '' around it.