Web Hosting Talk







View Full Version : Manually adding data to MySQL?


Johnburk
11-06-2005, 09:01 PM
I currently have a script that automaticly takes information and puts it into a database. I would like to add some data manually, but don't know how. The code is:

mysql_query("insert into host(name,code,ip,stime) values('$name','$code','$ip',now())");
if(mysql_insert_id())
{

How is it possible to manually add data?

Johnburk
11-06-2005, 09:46 PM
LOL. manually is

insert into host(name,code,ip,stime) values('$name','$code','$ip',now())");

Just replace $name','$code','$ip' with the values

Now the problem is, how do I add 400+ names, without having to copy and paste?


---p.s lol, easy answer to my own question, I replyed it because it looked hard and maybe other users might have the same problem, looking for the same solution---

BurakUeda
11-06-2005, 10:38 PM
Where are those 400+ data coming from?
another database? or you have them in a sort of text/csv file?

Johnburk
11-07-2005, 05:37 AM
I have them as text/csv


I use to have a script that did not work with mySQL and would store the name in a text file.

dollar
11-07-2005, 05:48 AM
Use something like EditPad pro that has regular expression support. With a few quick regex's you could format the data for a dump file and then just dump the data into the database.

Johnburk
11-07-2005, 06:01 AM
I currently use Editplus 2,

What are "a few quick regex's"?

I will download EditPad pro and try that.

dollar
11-07-2005, 06:04 AM
Few quick regular expressions to find the correct data, and edit the file to change it to mysql lines.

What does your current file look like?

Chrillek
11-07-2005, 06:04 AM
Maybe you can do it with "DBTools Manager"? I was using it for something similar once and it worked great.

Johnburk
11-07-2005, 06:07 AM
My current file looks like this,


agenda2006.nl
ajaxvoetbal.com
arbo-dienst.nl
arbobeleid.be
arbodienst.be
autotweedehands.com
b-boying.com
biopay.be
bushpresident.net
buyagun.net
camerasecurity.net
carsnew.net
chinaairline.nl
chinaexport.nl
disneylandhongkong.nl
download-vista.nl
ek2012.be
ek2016.be
emailhosting.be
eurostem.nl
eustem.nl
exportchina.nl
filmhuren.com
freepsp.nl
fundazakelijk.nl
goedkoophotels.nl
goedkoopreis.nl
goedkoopwijn.nl
2006duitsland.nl
2012londen.nl

dollar
11-07-2005, 06:11 AM
I thought you wanted to add name, IP, Code, etc.... Where is the rest of the data?

Chrillek
11-07-2005, 06:14 AM
You could do that by programming a simple php script to add'em all. Open the file, do some foreach stuff and "insert into" and you're done in a few seconds!

How to program the code? Ask a programmer! ;)

Johnburk
11-07-2005, 06:23 AM
There is no rest of data.

The old script just registerd the names and dumped them in a text file.

The new script will give evey site a uniqe code and log the IP of the person adding the site and the date.


For copying the old list to the database.... Code, IP and date are not important. Just the name.

dollar
11-07-2005, 06:28 AM
something like this:

In editpad pro, use this as the search string:

(.*+)\s

use this as the replace string (Be sure to put a return at the end so things aren't all on one line, it won't hurt anything to have them on one line, but it will be prettier with them on seperate lines.):

insert into host(name,stime) values('\1',now());


check Regular Expression, check Start from beginning, hit replace all (double check the first and last lines to make sure they are properly updated.

Johnburk
11-07-2005, 06:39 AM
Thank you, I am going to try editpro and let you know.

dollar
11-07-2005, 06:44 AM
More than welcome, if it doesn't work you're welcome to send me the file admin [at] justadollarhosting.com and I can do it for you.