www.webdeveloper.com
Results 1 to 10 of 10

Thread: General advice for a newcomer

  1. #1
    Join Date
    Mar 2005
    Location
    UK
    Posts
    37

    General advice for a newcomer

    I want to write a page with a limited feedback form - basically a yes/no poll with postcodes able to be logged. I've seen (and got) code (PHP) for a poll. Anyone got advice on a better or easier way to do it. Even better, anyone got any script that already fulfills this function. I'm not a techie so please go easy on me...

  2. #2
    Join Date
    Feb 2005
    Location
    BC, Canada
    Posts
    1,098
    Here, I'm not going to test this, but I'll write it out.


    Make a new HTML file, call it "form.html". Inside write:
    Code:
    <html>
    <body>
    <form action="poll.php" method="POST">
    <input type="hidden" name="poll" value="{pollname}">
    <input type="hidden" name="method" value="vote">
    <input type="hidden" name="options" value="2">
    <input type="radio" name="choice" value="1" checked>Yes<br>
    <input type="radio" name="choice" value="0">No<p>
    <input type="submit" value="Vote!">
    </form>
    </body>
    </html>
    Replace {pollname} with the name of the poll. We'll use it to record values.

    Now, make the file, "poll.php". Inside write this:
    PHP Code:
    <?php

    // This creates the file that holds the poll data, if it doesn't exist. It uses the OPTIONS element from the form to figure out how many possibilities there should be.
    if (!file_exists($POST['poll'].'.dat')) {
     
    $file fopen($POST['poll'].'.dat','a+');
     for (
    $i=0;$i<$_POST['options'];$i++) {
      
    fwrite($file,$i.'=0'."\n");
     }
     
    fclose($file);
    }

    if (@
    $_POST['method'] == "vote") {
     
    $data file($POST['poll'].'.dat');
     
    $temp explode('=',$data[$_POST['choice']]);
     
    $temp[1]++;
     
    $data[$_POST['choice']] = implode('=',$data[$_POST['choice']]);

     
    unlink($POST['poll'].'.dat');
     
    $file fopen($POST['poll'].'.dat','a+');
     for (
    $i=0;$i<$_POST['options'];$i++) {
      
    fwrite($file,implode("\n",$data));
     }
     
    fclose($file);
    }

    ?>
    Now, this will record data like this:
    0=5
    1=3
    Where the first number is the option, and the second is the amounts of votes it has recieved.

    [I honestly have no idea if this will work, as I haven't tested it, but it should.]

  3. #3
    Join Date
    Mar 2005
    Location
    UK
    Posts
    37
    Thank you! Will try it out...

    For the future of a site, any general advice over which server side technology is the most future proof / recommended?

  4. #4
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    PHP = free and easy.
    ASP = corperate and horrible
    CGI = nice, but without cookies the users is ignored


    I think that answers your question, PHP is the easiest and its free, it also has the fewest reported bugs and known errors.
    ASP is a coperate thing, mircosoft would put up patent on serverside technology to stop people from ignoreing ASP if they could, luckily they didn't develop it.
    CGI is nice, but unlike ASP and PHP you don't have easy methods of setting up cookies if the user don't have them enabled, a reason why many CGI sites that require cookies get less visitors.

  5. #5
    Join Date
    Jan 2003
    Location
    USA
    Posts
    687
    Originally posted by scragar
    CGI = nice, but without cookies the users is ignored
    ...
    ...

    ...
    CGI is nice, but unlike ASP and PHP you don't have easy methods of setting up cookies if the user don't have them enabled, a reason why many CGI sites that require cookies get less visitors.
    Hi, scragar...

    Would you mind explaining the above? Being a Perl CGI scripter, myself, I don't really understand what you are saying.

  6. #6
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    And me having been working with ASP for several years, I also dont know what your saying. You also didnt mention the two most powerful and industry-leading technologies, being the .NET framework and JSP.

    Regards.

  7. #7
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    if you use cookies on the users computer via CGI and they have them disabled CGI cannot (usualy) detect this and/or cover this in some way.

    ASP can be made to produce some form of protection from this but it's not secure, while PHP's is the best workaround I have seen.



    As for my statement about ASP it's driven purely by my harted of microslop.

  8. #8
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    Your statement is incorrent, though. It comes off making you look ignorant. You let very uneducated quarrels get in the way. ASP is free and easy to setup. ASP (and especially .NET) offer fantasitc security options/tools -- they have to considering their technologies are among the industry leaders.

  9. #9
    Join Date
    Mar 2005
    Location
    UK
    Posts
    37
    Other than reading from yourselves and gleaning info gradually from you, is there anywhere i can learn PHP to be able to add interactivity to my site myself? Any read made resources?

  10. #10
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    The best way is to buy a book. Or atleast borrow one from a local library. Resources on the WWW are often outdated and/or incorrect -- not to mention incomplete.

    www.php.net offers excellent (and official) learning resources. Other than that, try www.amazon.com

    Regards.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles