Announcement

Collapse
No announcement yet.

A wild PHP approaches!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    My leet Thievery Map
    My leet UT3 Map
    My leet AS Map

  • #3
    Guess i need to google better...

    Ill report my findings once im done digging thru this, thanks
    My leet Thievery Map
    My leet UT3 Map
    My leet AS Map

    Comment


    • #4
      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
      My leet Thievery Map
      My leet UT3 Map
      My leet AS Map

      Comment


      • #5
        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>
        My leet Thievery Map
        My leet UT3 Map
        My leet AS Map

        Comment

        Working...
        X