Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Problem Inserting Data into Table

Posted by Ajak (Ajak), 16 July 2005
I am using a web-site digital download program (http://reamdaysoft.com/magic-downloads/overview.html), which collects users email addresses. Users have the option of subscribing to a mailing list by ticking a check-box, the program returns the data as shown below (I don't know what the empty column is for):

"e-mail","Subscribe_to_Newsletter ",""
"abc@myway.com","on",""
"xyz@hotmail.com","off",""

Problem is, in the list of email addresses collected, the subscribed email addresses are mixed with the un-subscribed ones. I needed to get the subscribed email addresses into a separate list.

I created a MySQL table called mail, with 3 columns (e-mail, Subscribe_to_Newsletter, blank) & tried to insert the email addresses. There is no line break between the 2 records, so MySQL reads the insert as having 6 columns. I did this to get it to work:

INSERT INTO mail( email, Subscribe_to_Newsletter,blank)
VALUES (
"abc@myway.com", "on","" ),
("xyz@hotmail.com", "off", ""
);

However as I am expecting to capture, hundreds maybe thousands of email addresses, I can't edit each one. I would like to be able to manipulate the lines of text based on conditions, ie: if a line contains the word "off", then delete or move to another location. I am not a programmer but I don't think this is a difficult thing to do.

I have tried various text editors but can't seem to find one that will do this, any suggestions? or is there a way to load the data into MySQL?.  

Posted by Custard (Custard), 16 July 2005
Aha!, yes there is!

Have a look at the MySQL LOAD DATA INFILE syntax..

http://dev.mysql.com/doc/mysql/en/load-data.html

This should let you take a CSV file (or whatever) and map the fields to fields in a supplied table.

Let us know how you get on..

B

Posted by Ajak (Ajak), 17 July 2005
I ran this query in phpMyAdmin (I don't have shell access):

LOAD DATA INFILE 'info.csv'
INTO TABLE mail;

[nfo.csv (located in the httpdocs directory on the server)]
"e-mail","Subscribe_to_Newsletter ",""
"abc@myway.com","on",""
"xyz@hotmail.com","off",""

& got this error message:

"Error

SQL-query:

LOAD DATA INFILE 'info.csv' INTO TABLE mail

MySQL said: Documentation
#1045 - Access denied for user 'mail'@'localhost' (using password: YES)"

Posted by admin (Graham Ellis), 17 July 2005
It looks like you don't have File_priv for the account that you're using to log in to mysql.  

Easiest solution may be to obtain that priviledge (or log in through another user account that already has it if you happen to have multiple accounts set up for different operations.   If that's not going to be practical, you could write a script to generate SQL commands like the INSERT you quoted from the data file, then source those.

Posted by Ajak (Ajak), 20 July 2005
I solved the problem by loading the file into OpenOffice.org's Spreadsheet & using the Data Filter.

Thank's for the help.  



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho