...

View Full Version : writing to a txt file using the pipe symbol?



titch35
11-15-2007, 06:09 PM
i wrote this code to read from a text file using php, but when i go to add more info using a html form, it just adds the info but not in the right place.it needs to be in number order.


Any help please......

this is my text file:
|1 |11|21|31|41|51|71|81
|2 |12|22|32|42|52|72|82
|3 |13|23|33|43|53|73|83
|4 |14|24|34|44|54|74|84
|5 |15|25|35|45|55|75|85
|6 |16|26|36|46|56|76|86
|7 |17|27|37|47|57|77|87
|8 |18|28|38|48|58|78|88
|9 |19|29|39|49|59|79|89
|10|20|30|40|50|60|80|90

this is the php file in which i use to read this file.

<?php
$file = fopen("welcome.txt", "r");
if(!$file) {
print "error! The file could not be opened";
exit;
}
// read file and print, line by line


while(!feof($file))
{
$text=fgets($file);

if ($text!="M"&&$text!="F")

{
echo "$text
";
}


}
fclose($file);
?>
</body>
</html>


this is my append to file PHP script but isnt working right:

<?php
$customerName = $_POST['name'];

if(!$customerName) // If name is not entered show error message
{
echo "Please enter your name to register.";
exit;
}
else
{
$filename = "seats.txt"; // File which holds all data
$content = "$customerName\n"; // Content to write in the data file
$file = fopen($filename, "a"); // Open the data file, file points at the end of file
$filewrite = fwrite( $file, $content ); // Write the content on the file
fclose( $file ); // Close the file after writing

if(!$filewrite) echo "Couldn't write the entry.";
else
echo "You are now registered, Click below to continue.";
}
?>

</body>
</html>

Inigoesdr
11-15-2007, 06:18 PM
Post your form, an example of what you're submitting, and the unintended result. Also, I don't see any code dealing with numbers at all. Are you manually entering them?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum