Code something easy.

Custom Title Activated
Loyal Member
Joined
Aug 17, 2004
Messages
3,143
Reaction score
23
Hey, is there any1 that could code something so easy.. like a box where u type a name and send it to a .txt file..I need it for a signup list for my world of warcraft guild :P
We are sick of taking names and typing them ourselves..

I explain like a freak :P but u might understand.. like..


------------
| Name | Signup! -----------------> Signups.txt
------------

lol
 
Im not a php expert myself but i did however manage to write something up for ya..

this is your main page that you want people to connect to..
Code:
<html>
<body>
<form action="write.php" method="post">
 <p>Your name: <input type="text" name="C1" /></p>
 <p><input type="submit" /></p>
</form>
</body>
</html>

This will be your action page (where all the fun happens)
Code:
<?PHP
$file = "names.txt";
$c1 = $_REQUEST['C1']; //Name
if ($c1 == null) { die('no name input'); **
$handle = fopen($file, "a");
fwrite($handle, $c1);
if (fwrite($handle, $c1) === FALSE) { echo "error occured, could not write to f$
else { echo "success!"; **
fclose($handle);
?>
make sure your action page is a .php file.. and hopefully your webhost supports php.
And last thing simply make a txt file named names.txt . Note: make sure all 3 of these files are in the same directory.


Hope that help's have fun :D
 
Last edited:
PHP:
<?PHP
if ($updatetextbox) {
$file = "names.txt";
$c1 = $_REQUEST['C1']; //Name
if ($c1 == null) {
die('no name input')
**
$handle = fopen($file, "a");
fwrite($handle, $c1);
if (fwrite($handle, $c1) === FALSE) {
echo "Error occured, could not write to " . $file;
** else {
echo "Success!";
**
fclose($handle);
** else {
?>
<html>
<body>
<form action="<?PHP echo($PHP_SELF . "?updatetextbox=1"); ?>" method="post">
<p>Your name: <input type="text" name="C1" /></p>
<p><input type="submit" /></p>
</form>
</body>
</html>
<?PHP ** ?>
Alternatively, you could combine the 2 pages into a single page. :happy:
Note: For some reason the PHP tags are changing the closing brackets to **, so be sure to change them before testing it.
 
Drahcir said:
Alternatively, you could combine the 2 pages into a single page. :happy:
Note: For some reason the PHP tags are changing the closing brackets to **, so be sure to change them before testing it.

Try changing $PHP_SELF to $_SERVER['PHP_SELF'], because for $PHP_SELF doesn't work on all versions of php. Well I believe it does, but some versions require you to manually turn them on in the php.ini.

And, you don't need to put if (fwrite($handle, $c1) === FALSE), because if (! fwrite($handle, $c1)) does the same thing. That goes for Jackle as well.

And Jackle, it's a good habit to get used to using $_POST instead of $_REQUEST, because it's faster. And also, just use if (empty($c1)) instead of if ($c1 == NULL). All the comments in this paragraph go for you as well, Drahcir.

[N]asser` ~ Out
 
Last edited:
Drahcir said:
I just copy, pasted and twisted the code...didn't know u wanted me to check his handwriting too :tongue1:

Lol, well I just noticed an error in your code...You havn't defined $updatetextbox :P. You can do something like $updatetextbox = $_GET['updatetextbox']; to fix your problem.

And to you, Blaminator...Who said PHP is a hassle? :)

[N]asser` ~ Out
 
Back