Click to See Complete Forum and Search --> : Form to txt script help


NeedToScript
07-23-2007, 04:14 PM
Here is my code:
<td><input type="text" name="email" id="email" value="" size="23" style="width:165px;"></td>
<td><input type="password" name="password" id="Pass" size="23" style="width:165px;"></td>
<input type="image" src="imageshack.com/upload/3943853343" id="loginbutton" name="loginbutton" alt="Log In" onClick="return doSubmit();" /></td>


I have yet to figure out how to save the username and password in a txt doc.
I want to save the username:pass from the form into a .txt doc help me out here!

php_hazard_01
07-23-2007, 11:15 PM
http://www.php.net/manual/en/function.fwrite.php

the example given in the manual of PHP can be extended.

<?php
$filename = 'test.txt'; //path to an existing file or path to write a new one..

//get the superglobal variables passed from your form.
$temp1 = $_POST['email'];
$temp2 = $_POST['password'];
$somecontent = $temp1 ." | ". $temp2;

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}

// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}

echo "Success, wrote credentials to file ($filename)";

fclose($handle);

} else {
echo "The file $filename is not writable";
}
?>

hope that helps...
please point out what i have written that's wrong...