This is the output I'm getting from the $wpdb->show_errors from Wordpress, and the output of the Query.
WordPress database 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 '1' at line 1]
1
INSERT INTO wp_posts (
to_ping, post_author, pinged, comment_count, post_password, post_excerpt,
post_status, comment_status, ping_status, post_parent, menu_order,
post_content_filtered, post_type, post_mime_type, post_name, post_title,
post_content, post_date, post_date_gmt, post_modified, post_modified_gmt, guid)
VALUES (
'', '', '', '0', '', '', 'draft', 'open', 'open', '0', '0', '', 'page', '',
'test-page', 'This is a test!', 'This is where content goes...',
'2010-12-08 07:38:05', '2010-12-08 07:38:05', '2010-12-08 07:38:05',
'2010-12-08 07:38:05', 'http://localhost/wordpress/?page_id=')
There is literally a "1" on the first line. Remove it. "1" alone is not valid MySQL syntax..
remove 1 at the first line
query is perfect
Related
I have a database SQL table looking like this
[the database table]
So I'm trying to update this table simultaneously, such that one query updates multiple columns in multiple rows at once. The script looks like this
INSERT INTO teams
(id, team_name, matches_played, won, lost, points, goals_for, goals_against, goal_difference, last_match)
VALUES
('10', 'Manchester City', '3', '1', '', '3', '2', '0', '0', 'W'),
('5', 'Westham', '2', '', '1', '3', '0', '2', '-1', 'L')
ON DUPLICATE KEY UPDATE
team_name = VALUES(team_name),
matches_played = VALUES(matches_played),
won = VALUES(won),
lost = VALUES(lost),
points = VALUES (points),
goals_for = VALUES(goals_for),
goals_against = VALUE(goals_against),
goal_difference = VALUE(goal_difference),
last_match = VALUES(last_match);
My issue is. This code works perfectly on XAMPP MySQL server but not on workbench. What might the issue be?
I try to insert my data to some table's of database I have tried the following:
INSERT INTO tbl_18189 (a,b,c,d,e) VALUES ( '1', '4 B', '%', '0', '0')
INSERT INTO tbl_3823 (a,b,c,d,e) VALUES ( '24000', '30 M', '34%', '885', '12.05')
INSERT INTO tbl_67126 (a,b,c,d,e) VALUES ( '3.99 M', '10 B', '10%', '530', '14.41')
INSERT INTO tbl_4247 (a,b,c,d,e) VALUES ( '1', '170 M', '%', '271', '22.77')
INSERT INTO tbl_23838 (a,b,c,d,e) VALUES ( '320000', '400 M', '7%', '407', '6.91')
but I got
Error creating table: 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 'INSERT INTO tbl_38232 ...
where is the problem in my code
UNION ALL joins SELECTs and you have none in your example. Remove them.
INSERT INTO tbl_18189 (a,b,c,d,e) VALUES ( '1', '4 B', '%', '0', '0');
INSERT INTO tbl_3823 (a,b,c,d,e) VALUES ( '24000', '30 M', '34%', '885', '12.05');
INSERT INTO tbl_67126 (a,b,c,d,e) VALUES ( '3.99 M', '10 B', '10%', '530', '14.41');
INSERT INTO tbl_4247 (a,b,c,d,e) VALUES ( '1', '170 M', '%', '271', '22.77');
INSERT INTO tbl_23838 (a,b,c,d,e) VALUES ( '320000', '400 M', '7%', '407', '6.91');
This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 8 years ago.
Thank you for your comments on this error
INSERT INTO donors (
'institution',
'contact_person',
'first_name',
'last_name',
'affiliation',
'picture_link',
'email',
'birthday',
'sex',
'street',
'city',
'state',
'zip'
)
VALUES (
'',
'',
'Claire',
'Bowens',
'employee',
'http://las-americas.org/wp-content/uploads/2010/10/Claire-staff-photo.jpg',
'#',
'yyyy-mm-dd',
'female',
'',
'El Paso',
'Texas',
''
)
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 ''institution', 'contact_person', 'first_name', 'last_name', 'affiliation', 'p' at line 1
To enclose identifiers use backticks => `` `
In your code you used '.
INSERT INTO donors ( `institution`, `contact_person`, `first_name`, `last_name`, `affiliation`?, `picture_link`, `email`, `birthday`, `sex`, `street`, `city`, `state`, `zip`) VALUES ('', '', 'Claire', 'Bowens', 'employee', 'http://las-americas.org/wp-content/uploads/2010/10/Claire-staff-photo.jpg', '#', 'yyyy-mm-dd', 'female', '', 'El Paso', 'Texas', '' )
(Single) Quotes are just used for string literals.
A more detailed answer can be found in this question:
https://stackoverflow.com/a/11321508/1169798
remove the ' from your table fields like this.
INSERT INTO donors (
institution,
contact_person,
first_name,
last_name,
affiliation,
picture_link,
email,
birthday,
sex,
street,
city,
state,
zip
)
VALUES (
'',
'',
'Claire',
'Bowens',
'employee',
'http://las-americas.org/wp-content/uploads/2010/10/Claire-staff-photo.jpg',
'#',
'yyyy-mm-dd',
'female',
'',
'El Paso',
'Texas',
''
)
I am trying to build some address data from a number of different tables and come up with two returned datasets using a UNION query to remove duplicates. I am building the following SQL statement in PHP
$query = "
SELECT
l.UPRN,
(CONCAT(IF(o.ORGANISATION IS NULL, '', CONCAT(o.ORGANISATION, ' ')),
IF(l.SAO_TEXT IS NULL, '', CONCAT(l.SAO_TEXT, ' ')),
IF(l.SAO_START_NUMBER <> 0, SAO_START_NUMBER, ''),
IF(l.SAO_START_SUFFIX IS NULL, '', SAO_START_SUFFIX),
IF(l.SAO_END_NUMBER <> 0, CONCAT('-', SAO_END_NUMBER), ''),
IF(l.SAO_END_SUFFIX IS NULL, '', l.SAO_END_SUFFIX),
IF(l.PAO_TEXT IS NULL, '', CONCAT(' ', l.PAO_TEXT, ' ')),
IF(l.PAO_START_NUMBER <> 0, PAO_START_NUMBER, ''),
IF(l.PAO_START_SUFFIX IS NULL, '', PAO_START_SUFFIX),
IF(l.PAO_END_NUMBER <> 0, CONCAT('-', PAO_END_NUMBER), ''),
IF(l.PAO_END_SUFFIX IS NULL, '', l.PAO_END_SUFFIX),
IF(s.STREET_DESCRIPTION IS NULL, '',
CONCAT(' ', s.STREET_DESCRIPTION, ' ')),
IF(s.LOCALITY_NAME IS NULL, '', CONCAT(s.LOCALITY_NAME, ' ')),
IF(s.TOWN_NAME IS NULL, '', CONCAT(s.TOWN_NAME, ' ')),
IF(s.ADMINISTRATIVE_AREA IS NULL, '',
CONCAT(s.ADMINISTRATIVE_AREA, ' ')),
b.postcode_locator)
) AS single_address_label
FROM addbaseprem.abp_lpi l
INNER JOIN addbaseprem.abp_blpu b
ON b.UPRN = l.UPRN
INNER JOIN addbaseprem.abp_street_descriptor s
ON s.USRN = l.USRN
LEFT JOIN addbaseprem.abp_organisation o
ON o.UPRN = l.UPRN
WHERE l.LOGICAL_STATUS = 1
";
It is working pretty well in that I am getting my UPRN and single_address_label columns returned. I'm having a problem with the following part though
IF(s.ADMINISTRATIVE_AREA IS NULL,'',CONCAT(s.ADMINISTRATIVE_AREA,' ')),
What I would like to happen is not to CONCAT the ADMINISTRATIVE_AREA value if it is the same as the TOWN_NAME value eg i would like something like
IF(s.ADMINISTRATIVE_AREA IS NULL,'',IF((s.ADMINISTRATIVE_AREA == s.TOWN_NAME),'',CONCAT(s.ADMINISTRATIVE_AREA,' ')),
I have tried a few variations of OR != and so on but to no avail - I can't seem to get the code right and keep getting a syntax error. I don't know if I'm trying to do something that's just not possible or just making a schoolboy mistake. It's taken quite a time to get this far...
All help or advice gratefully received.
Try:
IF(s.ADMINISTRATIVE_AREA IS NULL OR s.ADMINISTRATIVE_AREA = s.TOWN_NAME,'',CONCAT(s.ADMINISTRATIVE_AREA,' '))
You can also simplify many of the pieces by using IFNULL:
IFNULL(column, '')
is equivalent to:
IF(column IS NULL, '', column)
For some reason my code is giving me an error, and I can't figure out why. Here's the error:
INSERT INTO organization (org_name, add_1, add_2, city, state, zip, url, email, phone, contact, hours, file_loc, notes, description, group) VALUES('testmi', '333', '', '', 'MI', '', 'www.blah.com', '', '888-999-2222', '', '', '', '', '', 'Michigan')QUERROR 3You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group) VALUES('testmi', '333', '', '', 'MI', '', 'www.blah.com', ''' at line 1
And here's the code:
$sqlInsertOrg = "INSERT INTO organization (org_name, add_1, add_2, city, state, zip, url, email, phone, contact, hours, file_loc, notes, description, group)
VALUES('".$org_name."', '".$add_1."', '".$add_2."', '".$city."', '".$state."', '".$zip."', '".$url."', '".$email."', '".$phone."', '".$contact."', '".$hours."', '".$file_loc."', '".$notes."', '".$description."', '".$group."')";
GROUP is a reserved keyword in MySQL. Escape it with backticks (`) and you'll be fine.
INSERT INTO organization (org_name, ... `group`) ...