# [web] Problems with creating files from php script. [Solved]

This topic is 4281 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a php file that im using to create a txt file, i want to save the results from a mysql table in the file. I stuck in a loop that displays the data on the page. I wanted it to display the data, then write the content to the txt file. link to the file is http://www.4thleveldesigns.com/Warehouse/buffer.php. <?php require_once('Connections/warehouse.php'); ?> <?php mysql_select_db($database_warehouse,$warehouse); $query_Details = "SELECT * FROM Details";$Details = mysql_query($query_Details,$warehouse) or die(mysql_error()); $row_Details = mysql_fetch_assoc($Details); $totalRows_Details = mysql_num_rows($Details); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <table border="1" class="Title_text"> <tr> <td>Serial</td> <td>TechName</td> <td>TechID</td> <td>JobNo</td> <td>Date</td> <td>Status</td> <td>ID</td> </tr><?php ?> <?php do { ?> <tr> <td><?php echo $row_Details['Serial']; ?></td> <td><?php echo$row_Details['TechName']; ?></td> <td><?php echo $row_Details['TechID']; ?></td> <td><?php echo$row_Details['JobNo']; ?></td> <td><?php echo $row_Details['Date']; ?></td> <td><?php echo$row_Details['Status']; ?></td> <td><?php echo $row_Details['ID']; ?></td> </tr> <?$fp = fopen( "TECH_BUFFER/TECH_BUFFER" & date("Y-m-d ")& "zzz.txt", "a" ); if(!$fp) { echo "Couldn't open the data file. Try again later."; exit; }$inputString = $row_Details['Serial'] +$row_Details['TechID'] + "\n"; fwrite( $fp,$inputString ); ?> <?php } while ($row_Details = mysql_fetch_assoc($Details)); ?> </table> <? fclose( $fp ); ?> </body> </html> <?php mysql_free_result($Details); ?> [Edited by - pinochio53 on March 30, 2006 11:24:49 PM]

##### Share on other sites
What is the actual problem?
What does the system log say?
What does php.log say?
What does the web page say?
What do you expect to happen?
What actually happens?

##### Share on other sites
The problem is that it only writes one line unto the page.

'641699507676'<-- what it outputs to the file.

The webpage outputs just fine, it shows whats in the table, but that info doesnt go into the file, only that one line does.

Im expecting the Output to be like this:
'
001311BA4F8F 5105
XC9516DB0665 9950
XC9516DB0665 7676
001311BA4FEF 5243
'

##### Share on other sites
The thing which occurs to me, is it looks like you're using & for string concatenation:

\$fp = fopen( "TECH_BUFFER/TECH_BUFFER" & date("Y-m-d ")& "zzz.txt", "a" );

This is probably not what you intended.

I don't know whether & does string concatenation in PHP - probably not. I think you must be confusing it with VB.

It's not creating a file called "0" somewhere, is it?

Mark

##### Share on other sites
come to think of it, i think it has, in the same directory where the buffer.php resides.

and it has at one time also created a file called 2006.

What i want this script to do is to create the text file with the file name TECH_BUFFER Ddmmyy hhmmss zzz.txt <-- meaning i want it to automatically add the date and time to the file name in that format. also i want to output to that file like this:

001311BA4F8F 5105
XC9516DB0665 9950
XC9516DB0665 7676
001311BA4FEF 5243

i want it to have that amount of space in between the values. I also want it to zip that txt file after its created. That is my ultimate goal with this script. some suggestions and help would be appreciated.

##### Share on other sites
Guys, i figured out the problem by myself, my problem was that i wasnt seperating my data into different strings. I was trying to put it in one big long string, which didnt really work, so i tried doing it as different string variables and then combining them in the fwrite statement, which worked :). Now i just have to figure out to have the script zip the txt file once its been created.

##### Share on other sites
Guys, i figured out the problem by myself, my problem was that i wasnt seperating my data into different strings. I was trying to put it in one big long string, which didnt really work, so i tried doing it as different string variables and then combining them in the fwrite statement, which worked :). Now i just have to figure out to have the script zip the txt file once its been created.

##### Share on other sites

This topic is 4281 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628710
• Total Posts
2984319

• 23
• 11
• 9
• 13
• 14