SunQuest
 
           General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 19th, 2003, 03:39 AM
obi obi is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 17 obi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 9 m 5 sec
Reputation Power: 0
Angry help writing text file contents into DB

I have been trying to read the contents off three(3) text files comprising phonenumbers, names and addresses, and write them into a database table of three fields of similar names.Except I keep getting the unwanted results with these codes.Can somebody please look and help urgently?Thanks.Appreciate.
The code I used:

<?php
include "db.php";

$nu = @fopen("phonenumber.txt", "r")
or die("<br>Failed to open file: <i>phonenumber.txt</i>.");
$array = file("phonenumber.txt");


$nu = @fopen("userlist.txt", "r")
or die("<br>Failed to open file: <i>userlist.txt</i>.");
$array1 = file("userlist.txt");


$nu = @fopen("password.txt", "r")
or die("<br>Failed to open file: <i>password.txt</i>.");
$array2 = file("password.txt");




foreach ($array as $fd)
{
foreach ($array1 as $fg)
{
foreach ($array2 as $fx)

{
$myquery = "INSERT into totalled (phoneNumber, user, password) VALUEs ('$fd', '$fg', '$fx')";
$result = mysql_query($myquery, $ok);
if (!$result)
{
echo "Nothing";
}

}
}
}

?>

Last edited by obi : March 19th, 2003 at 04:07 AM.

Reply With Quote
  #2  
Old March 19th, 2003, 03:37 PM
rickwright rickwright is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Nova Scotia
Posts: 27 rickwright User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I don't know what your results are, but:

Why don't you try replacing
$array = file("phonenumber.txt");
with
$fd = file("phonenumber.txt");

Try doing your inserts one at a time.

Try echo mysql_error(); after the query

Reply With Quote
  #3  
Old March 20th, 2003, 02:15 AM
obi obi is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 17 obi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 9 m 5 sec
Reputation Power: 0
ooops
Got it afterall courtesy of a friend.Thanks for helping out rickwright. Just so it doesnt fry another fellows brains like it did mine, what works should go like this:

<?
include "db.php";

$nu = @fopen("phonenumber.txt", "r")
or die("<br>Failed to open file: <i>phonenumber.txt</i>.");
$array = file("phonenumber.txt");


$nu = @fopen("userlist.txt", "r")
or die("<br>Failed to open file: <i>userlist.txt</i>.");
$array1 = file("userlist.txt");


$nu = @fopen("password.txt", "r")
or die("<br>Failed to open file: <i>password.txt</i>.");
$array2 = file("password.txt");


for ($i=0; $i<count($array); $i++)
{
$myquery = "INSERT into totalled (phoneNumber, user, password) VALUEs ('$array[$i]', '$array1[$i]', '$array2[$i]')";
$result = mysql_query($myquery, $ok);
if (!$result)
{
echo "Nothing";
}
}

?>

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > need help with this


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway