Black Cat Forums   Alien Swarm - Steampowered Forums
Alien Swarm 2K4 - ThieveryUT
Black Cat Games - TTLG Forums

Go Back   Black Cat Forums > Community Forums > Troubleshooting & Technical Help

Reply
 
Thread Tools
Old 10th Mar 2011, 12:25 PM   #1
Schleicher
Member
 
Schleicher's Avatar
 
Registered: Jun 2003
Location: not in the Playboy Manor =(
Posts: 3,174
A wild PHP approaches!

Ok so i got a html user form. Entered stuff gets stored with $_POST php variables. How do i make the user form write those variables into a .txt document (or somesuch) e.g. i enter something into the form and it gets written into a .txt file.

Here is the thing. Im using xampp to fart around so its directory is xampp/htdocs/test/ and the file is test.php. The "ouput" file would be something like test.txt

Its prolly all kinda ugly (formattings on purpose tho) but im just striving for basic understanding here. Bonus points if ya can tell me how to read out of a file and have the data displayed (with an if-echo butttan and form just like below).

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>test</title></head>
<font face=verdana><body bgcolor="">

<center><h1><font color=red><b>Zeugs</b></font color=red></h1></center>
<br><br><br>

<u><b>Hier Zeugs eingeben</b></u> :
<br><br>

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<Table border=1 bgcolor=yellow>
<tr>
<td>Eingabe 1 :</td><td><input type=text maxlength=30 name="eingabe1"></td>
</tr>
<td>Auswahl :</td><td><select maxlength=30 name="auswahl">
	<option>Bitte Auswählen &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </option>
	<option>2</option>
	<option>3</option></select></td>
</table>
<br><br>
<input type=submit name="senden" value="Senden">
</form>
<br><br>



<?php

#variablen
	$senden = $_POST["senden"];
	$eingabe1 = $_POST["eingabe1"];
	$auswahl = $_POST["auswahl"];
#variablen

echo $eingabe1."<br><br>";
echo $auswahl."<br><br>";
?>

<hr style="color:red;background:red;height:15px">
<br><br>

<center><table border=1 bgcolor=red>
<tr>
<td bgcolor=yellow>Eingegeben:</td><td bgcolor=white value="           "> <?php if($senden){echo $eingabe1;}?> </td>
</tr><tr>
<td bgcolor=green>Ausgewählt:</td><td> <?php if($senden){echo $auswahl;}?> </td>
</tr>
</table></center>

</body>
</html>
this took me like one hour s.s
Schleicher is offline   Reply With Quote
Old 10th Mar 2011, 12:56 PM   #2
Carth
Member
 
Carth's Avatar
 
Registered: Jun 2004
Location: UK
Posts: 3,577
http://www.php.net/manual/en/function.fopen.php
http://www.php.net/manual/en/function.is-writable.php
http://www.php.net/manual/en/function.fwrite.php
http://www.php.net/manual/en/function.fclose.php

OR

http://www.php.net/manual/en/functio...t-contents.php
__________________
I think I can love you
Let's facwe the future together
Carth is offline   Reply With Quote
Old 11th Mar 2011, 07:50 AM   #3
Schleicher
Member
 
Schleicher's Avatar
 
Registered: Jun 2003
Location: not in the Playboy Manor =(
Posts: 3,174
Guess i need to google better...

Ill report my findings once im done digging thru this, thanks
Schleicher is offline   Reply With Quote
Old 13th Mar 2011, 06:40 AM   #4
Schleicher
Member
 
Schleicher's Avatar
 
Registered: Jun 2003
Location: not in the Playboy Manor =(
Posts: 3,174
Last one did it. Totally unformated but i think if i try to figure how to write to an excel table or somesuch in an organized manner ill just explode.

More questions later...maybe
Schleicher is offline   Reply With Quote
Old 14th Mar 2011, 11:10 AM   #5
Schleicher
Member
 
Schleicher's Avatar
 
Registered: Jun 2003
Location: not in the Playboy Manor =(
Posts: 3,174
Something like this was the solution, a simple form saving stuff into an .csv file. Internets is hard :/

Code:
<html>
<head><title>Excel-Datei schreiben</title></head>
<body>
<form action="<?php $_SERVER["PHP_SELF"]?>" method="POST">

<input name=datum size=50 type=hidden value="<?php echo date("d.m.y"); ?>">
<input name=zeit size=50 type=hidden
value="<?php echo time("dd.mm.yyyy"); ?>">

Nachname: <input name=nachname size=50><br>
Vorname: <input name=vorname size=50><br>
eMail:<input name=email size=50><br>
Newsletter: <input type=checkbox checked name=news size=50><br>

<br><br>
<input type=submit name"Senden" value ="Abschicken">
</form>

<?php

#Variablen
$vname = $_POST["vorname"];
$nname= $_POST["nachname"];
$zeit = $_POST["zeit"];
$datum = $_POST["datum"];
$email = $_POST["email"];
$checker = $_POST["news"];
$sk = ";";
$ausgabe = $datum.$sk.$zeit.$sk.$vname.$sk.$nname.$sk.$email.$sk.$checker."\n";




# Ausgabe
#echo $ausgabe;

$fp = fopen("logfile.csv","a");
fputs($fp, $ausgabe);
fclose($fp);
#echo "<P>Das ist der Inhalt der Log-Datei:</P>";
#readfile("logfile.csv");
?>


</html>
Schleicher is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Komag's Contest 5 approaches Sneaky1Kenobi Community Chat 6 4th Mar 2004 01:48 AM
*** RLF DEFEATS NASTY EVIL WILD BILL AND HIS BOYS *** Mad_Gerbil Community Chat 19 13th Jan 2003 09:34 AM


All times are GMT -5. The time now is 04:31 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, vBulletin Solutions, Inc.