Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie.........Flat File and php

Status
Not open for further replies.

vafishing

Programmer
Joined
Jul 18, 2001
Messages
35
Location
US
I am trying to load a flat file to a webpage using the following code:
$BlockedFile = fopen($BlockedFileName,"r");
a null $BlockedFile is an error
if (feof($BlockedFile)) {}
$DBLink = mysql_connect('localhost',$SVSiteDatabase,$SVDatabaseUser,$SVDatabasePasswd);
$SiteDB = mysql_select_db($SVSiteDatabase);
while (!feof($BlockedFile) {}
$RecordIn = fgets($BlockedFile);
$FirstName = addslashes(trim(substr($RecordIn,0,20)))
$SQLStmt = "select Id from Users where LastName='$LastName' and FirstName='$FirstName' and StreetAddress='$StreetAddress';
$UserResult = mysql_query($SQLStmt) or die("Unable to get User Result using '$SQLQuery'...");
$TimeStamp = date("YmsHis");
$SQLStmt = "insert into Users set LastName='$LastName', ...";
The flat file is in the form of a web page with a url of

My question is will I need to save this file in my home directory and save as a.tab file or should the script be able to pull the data directly from the url. When I attempt to use the code in a blank html page with embedded ?>php I do not get any errors when I load the page, however I get no data either. Any suggestions? Also will I need to pull the flat file into mysql?
 
while (!feof($BlockedFile) {} - loop forever?
 
I got ARKM response meaning that I must adjust the curly brackets to aoid endless looping. I guess what I am looking for is a way to pull a tab delimited file "flat file" from a web site to my web site. The code needs to adjust for blanks if there are any. Essentially my tab file has some entries that have blanks. I need to account for it and need to be able to update and add records to my site
 
No, you need to use curly brackets in some way that is meaningful.

For example, this code:

for ($counter = 1; $counter <= 10; $counter++)
{
print $counter . &quot;\n&quot;;
}

will print something like:
1
2
3
...
8
9
10


This code:

for ($counter = 1; $counter <= 10; $counter++) {}
print $counter . &quot;\n&quot;;

Will print:
11


In the second case, since you have nothing inside the brackets, the code just spins its wheels 10 times then prints the value that caused it to stop spinning its wheels.


Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top