Current location: Hot Scripts Forums » Programming Languages » PHP » using PHP to insert to mysql


using PHP to insert to mysql

Reply
  #1 (permalink)  
Old 02-05-04, 03:18 PM
sylunt1 sylunt1 is offline
New Member
 
Join Date: Feb 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
using PHP to insert to mysql

Hello.

I have been doing manual entry of items one at a time thru phpmyadmin and it's beginning to become tedious. What I want to do is this:

I have a huge list of items that I want to put into a table. For security reasons, I can not import the text file directly into mysql. Is there a way to do this with php? I pretty much know that it can be done, just how to do it is the question.

Thanks,
Chris

www.brew-monkey.com
Reply With Quote
  #2 (permalink)  
Old 02-05-04, 11:22 PM
nd2 nd2 is offline
Wannabe Coder
 
Join Date: Jun 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
the format of the text file whould help greatly.
__________________
IonCMS (Coming Soon.)
http://ioncms.com
--
Ncaster (Free php/mysql cms)
http://ncaster.cjb.net
Reply With Quote
  #3 (permalink)  
Old 02-06-04, 09:55 AM
sylunt1 sylunt1 is offline
New Member
 
Join Date: Feb 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by nd2
the format of the text file whould help greatly.

There are 3 fields...
id countryabv country

I can format it how ever but now its just a list

the ID field should be set to null correct - to get the auto increment to do its job. The other fields are just varchars. They are in an excel file at the moment.



ex:
null AS American Samoa


Thanks.

Chris
Reply With Quote
  #4 (permalink)  
Old 02-06-04, 10:12 PM
tltran tltran is offline
Newbie Coder
 
Join Date: Jan 2004
Location: Montreal
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by sylunt1
There are 3 fields...
id countryabv country

I can format it how ever but now its just a list

the ID field should be set to null correct - to get the auto increment to do its job. The other fields are just varchars. They are in an excel file at the moment.



ex:
null AS American Samoa


Thanks.

Chris
Can you give us more details about your files,

Like

File 1 content:
1;Canada;America;
2;USA;America;
3;China;Asia;
4;France;Europe;

If so we can help you to create a script to read your text file and import your data into a database, otherwise we wont be able to help you.
__________________
Thanh Liem Tran
When You have to run, you have to run
http://www.irunsoft.com
Reply With Quote
  #5 (permalink)  
Old 02-06-04, 10:20 PM
tltran tltran is offline
Newbie Coder
 
Join Date: Jan 2004
Location: Montreal
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
suppose your data are store in a file with the following format

file1.txt
NULL;CA;Canada;
2;US;Units-States;

With php and mysql:
First make a simple connexion to your database..
Use the following function to to read a file and insert your data into database.

function importMyData($file_name) {

$t_file = file($file_name); // get data from the file
// for each line of the file do
for ($i=0; $i<count($t_file); $i++) {
$t_line = explode(";",$t_file[$i]);

$sql = "insert into (id, code, name)
values (".$t_line[0].",'". $t_line[1]."','". $t_line[2]."')";
mysql_query($sql,$cnx);
}
}
__________________
Thanh Liem Tran
When You have to run, you have to run
http://www.irunsoft.com
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
Generating PHP code for MySQL ptesone General Advertisements 1 02-03-04 08:26 AM
Generating external js subcategory list from MySQL using PHP NanoEntity PHP 0 12-15-03 09:08 AM
[HELP!] Automatically insert emails into mySQL archive CIRESTodd PHP 1 12-12-03 03:34 PM
PHP to MySQL script question...(using a field to update info in MySQL) DisneyFan25863 PHP 4 11-02-03 03:31 AM


All times are GMT -5. The time now is 08:19 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.