Results 1 to 8 of 8

Thread: Web Site Input

  1. #1
    Junior Member
    Join Date
    Mar 2004
    Posts
    14

    Web Site Input

    I would like to set up some kind of a service with which a webserver can accept data and can save it to a local file(s). The data is going to be comments, tests, and other things.

    Very simply, I need to have a form on a web site that when submitted, will export the data either into a database, text file, what ever is easiest to do.

    I was looking at a few ways to do this, and they all discussed setting up a lot of new services, such as php, SQL, ASP, and other things. I was hoping that there would be some way to do this with something more simple that is already in Apache. Web server is Apache 2.0 on Win2k3 Ent. And no, I cannot change either of these things, it's for school and it is what the instructor wants.

    I understand that some kind of server side processing is needed, but I would like to try to get this accomplished as easily as possible.

    I have full admin rights and access to server box, but I don't want to have to work on it for hours to get this input thing up and running.

    If you chose to respond, please be descriptive, I have never set up anything like this before besides just a default phpBB + MySQL install in which I followed a page of instructions.

  2. #2
    You will need at least php...I'm pretty sure. You can make a form in HTML that links to a php script which can then write the data from the form into something like a text file.
    form->php->.txt

    Very simply, I need to have a form on a web site that when submitted, will export the data either into a database, text file, what ever is easiest to do.
    Install php in your webserver, follow the apache instructions in the PHP docs, and write a script that will let you write to the textfile. Don't forget to change the text file permissions so its possible.

    BTW there is a web dev forum on this site as well.

    http://www.ucalgary.ca/~sukhan/mp3/mp3_infosend.php

    that link uses a plugin for winamp that will work with PHP to update a .txt file with your currently playing song. You can strip it down so it simply writes to a file, without the plugin crap.

  3. #3
    Junior Member
    Join Date
    Mar 2004
    Posts
    14
    If I used php, how much code would I have to use to be able to define a variable, send input to it, and save it to a text file? Or, without me having to learn php for this one thing, could someone else tell me what code I would have to include into the html page to do what I want? After I installed and enabled php in apache.

  4. #4
    Senior Member
    Join Date
    Jan 2002
    Posts
    227
    It's simple. You will have some html with form - for example something like this:
    Code:
    ...
    <form method="post" action="./save.php" />
    <input type="text" name="inputtext" />
    <input type="submit" value="submit" />
    ...
    and save php could be something like this:
    PHP Code:
    ...
    $f=fopen("data.txt","w");
    fputs($f,$inputtext);
    fclose($f);
    unset(
    $inputext);
    ... 
    more can be found at php.net and w3schools.

    Good luck and feel free to have more questions.
    http://promote.opera.com/small/opera94x15.gif

    [gloworange]Sun7dots[/gloworange]

  5. #5
    Senior Member
    Join Date
    Aug 2001
    Posts
    251
    (Phew, sun7dots didn't steal all my thunder, so I'm still going to hit post)

    Its easy in PHP, as that is exactly the kind of thing it was meant to do.

    Take a look at:
    http://codewalkers.com/tutorials/5/1.html

    from Codewalkers (if you couldn't tell by the url...)

    That article got me started with PHP. Before reading that article I hadn't written any code since the C class I took 2 or 3 years ago..., but I've found that even that little bit of knowledge has seriously sped up my learning curve. PHP is nice because it is relatively forgiving for small projects, but like all things the greater the scale the more you have to be careful.

    I don't know about Windows, but on both my *nix box and my MacOS X laptop installing/configuring php was REALLY easy.

    And, when all else fails, google! I know there is tons of stuff about Apache/PHP on Windows out there, because everytime I try to find something I have to skip over all that crap. There is tons of info out there, as I can think of atleast 5 sites that I frequent for tutorials and articles about PHP off the top of my head, and my memory is terrible.

    PHP (less a place for tutorials and more a place for the manual
    Zend Tutorials
    phpfreaks
    phpbuilder

    I image that Jupiter Media maintains somekind of php tutorial site somewhere, what it is, I wouldn't be able to tell you right now.

    Anyway, short of writing the code for you, I've given you what I can think of at this particular moment.

    (One of these days I'll make a lucid post...)

    Oh, the hardest thing of working with mySQL in php is the actual SQL queries themselves. Having never used a database before writing a database driven website, I pulled some of my hair out. Once you get the hang of it though, you start finding really handy functions.

    Go nuts,
    Dhej
    The owl of Minerva spreads its wings only with the falling of dusk. -Hegel

  6. #6
    Senior Member
    Join Date
    Jan 2003
    Posts
    3,915
    Hey Hey,

    I'll post the same as everyone else has, but I'll post the complete thing from start to finish. I wrote this out when I wanted to create a simple guestbook that didn't require a back-end database, just a nice and simple flatfile. This was the resultant code.

    This form allowed for user input.
    Code:
    <table width="100%">
    <tr>
    <td>
    <form method="post" action="core.php?Link=write_msg">
    At This time ,'s cannot be used. Hopefully this bug will be fixed soon.
    <table>
    <tr>
    <td>
    Name:</td><td><input type="text" name="name"><br></td></tr><tr><td>
    E-Mail:</td><td><input type="text" name="email"><br></td></tr><tr><td>
    Website:</td><td><input type="text" name="website"><br></td></tr><tr><td>
    Comment:</td><td><input type="textarea" name="comment"><br></td>
    </tr>
    </table>

    This code would take the form values and write them to a text file.
    Code:
    <?php
    $post =  "$name , $email, $website, $comment";
    $filename = "\webshare\wwwroot\posts.txt";
    $fp = fopen($filename, "r");
    $post2 = fread($fp, filesize ($filename));
    $post3 = $post2 . "\n" . $post;
    fclose($fp);
    $filename = "\webshare\wwwroot\posts.txt";
    $fp = fopen($filename, "w");
    fputs($fp, $post3);
    fclose($fp)
    ?>
    This could would display the textfile back to the user.
    Code:
    <OBJECT id=msg CLASSID="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">
         <PARAM NAME="DataURL" VALUE="posts.txt">
         <PARAM NAME="UseHeader" VALUE="True">
    </OBJECT>
    <TABLE ID=posts datasrc=#msg>
       <TBODY>
         <TR>
           <TD>Name:<SPAN DATAFLD="Name"></SPAN></TD>
         </TR>
         <TR>
         	<TD>E-Mail:<SPAN DATAFLD="Email"></SPAN></TD>
         </TR>
         <TR>
         	<TD>Website:<SPAN DATAFLD="WebSite"></SPAN></TD>
         </TR>
         <TR>
           <TD>Comment:<SPAN DATAFLD="Comment"></SPAN> <br><hr><br></TD>
         </TR>
       </TBODY>
    </TABLE>
    </DIV>
    Now this code obviously isn't the cleanest, I wrote this back when I was still new to html and have never modified it, but it does work quite nicely.

    Peace,
    HT

  7. #7
    Junior Member
    Join Date
    Mar 2004
    Posts
    14
    Thank you everyone, exactly what I was looking for.

  8. #8
    Webius Designerous Indiginous
    Join Date
    Mar 2002
    Location
    South Florida
    Posts
    1,123
    *xmaddness contimplates posting an entire PHP/MySQL solution to this question.





    Its good to see people other than the same 3 or 4 answering questions in this forum.


    Let us know how it goes Nick!


    www.planetmaddness.com

    xmad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •