...

View Full Version : HELP! Can't Write To Text File. Nothing Happens



Pianoman993
07-24-2007, 06:04 PM
Here are my two files. One contains the script that sends an array of information and stores it in a text file named log.txt.

Here is the form page.


<html><head><title>Add Users</title></head>
<body>

<form action="added.php" method="post">
Register <input type="text" size="3" name="newusers" /> users to nuance_cd log.<br />
<input type="reset" value="Clear" /><input type="submit" value="Generate IDs and PWs" />
</form>

</body>
</html>

Here is the .php page


<html><head><title>Add Users</title></head>
<body>

<?php

if ( isset ($_POST['submit'])) {

$newusers = $_POST['newusers'];

$anewusers = array();

$fp = fopen('log.txt', 'a+'); //***added change here

for ($num = 1; $num <= $newusers; $num++) {
$username = time() . rand(0, 4596);
$password = time() . rand(0, 4596).'a';
$data = $username . "\t" . $password . "\r\n";
$anewusers[] = $data;
fwrite ($fp, $data."\r\n");
}//close loop
fclose ($fp);

foreach ($anewusers as $value) {
print $value . '<br />\n'; }

} else { print 'You forgot to fill in some information';}


?>

</body>
</html>

Anyone who can solve the problem of why no error messages appear when no information is entered and why the log remains empty is a God. PLEASE HELP!

_Aerospace_Eng_
07-24-2007, 06:15 PM
Have you chmodded the file with the correct write permissions? 777 is the common one but 666 should work. Its a little more secure.

CFMaBiSmAd
07-24-2007, 10:04 PM
If you enter a number or not on the form, with the code you posted, the "You forgot to fill in some information" will always be displayed, because your submit button does not have a name and the isset ($_POST['submit'])) will never be true.

If you are not getting these results, then are you sure the .php file is named the same as the action="..." parameter on the form or is php installed and working on your server.

Once you correct the lack of a name="..." parameter for the submit button, your code works (at least it did on my test system.)

Pianoman993
07-25-2007, 11:54 PM
CFMaBiSmAd YOU ARE LEGEND. YOU HAVE DONE WHAT 4 OTHER FORUMS HAVE FAILED TO DO.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum