Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    133
    Thanks
    2
    Thanked 0 Times in 0 Posts

    help making a form

    Can someone help me make a form that updates a list of names/#s?

    When I try to experiment with the form functions it loads another page that the list is located on; I want the form and the list to be on the same page.

    For example:
    user: njfail
    #: 111
    Submit (click)

    Then below that it updates the list of users with:
    njfail #111

    (the # is not related in anyway to the problem here).

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Not enough information.

    Do you have some sort of database?

    Do you have an actual form you can show us, along with some PHP scripting?

  • #3
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,916
    Thanks
    15
    Thanked 227 Times in 227 Posts
    This is his previous post on this issue:

    Forms that update a list

    Personally I think it would be a lot simpler to keep the separate form and just code the page so that it returns to the index.php page.

    PS: Just the other day I wrote up a nice little login page for two entries. I might be a good start for your project. You just need to make a blank file, players.php, with the right permissions to see if it works for you. A lot needs to be added, such as checking the entries and reading the file to the index page in the format you need, but that's all very straightforward code.

    PPS: Added some code to make it function without errors. Needs more checking and code to write to the page..
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" 
        "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta content="text/html; charset=utf-8" http-equiv="content-type">
    <script type="text/javascript">
    //Alerts to errors.
    window.onerror=function(msg, url, linenumber){var logerror='Error message: ' + msg + '. Url: ' + url + 'Line Number: ' + linenumber;alert(logerror);return false}
    </script>
    <script type="text/javascript">
    function showLogin()
        {
        var m = document.getElementById("mylogin");
        m.style.display="block";
        var c = document.getElementById("cover");
        c.style.display="block";
        c.style.width="100%";
        }
    function hideLogin()
        {
        var m = document.getElementById("mylogin");
        m.style.display="none";
        var c = document.getElementById("cover");
        c.style.display="none";
        c.style.width="0";
        }
    </script>
        <title></title>
    <style type="text/css">
    html{background:#333}
    body{width:900px;margin:auto;margin-top:40px;color: White}
    body a {color: #aff}
    #mylogin
    {
    background: #369;
    padding:20px;
    width:300px;
    height:auto;
    position:absolute;
    z-index:100;
    left:50%;
    margin-left: -150px;
    top:50%;
    margin-top: -160px;
    border: 2px solid #fff;
    -moz-border-radius: 16px;
    -webkit-border-radius: 16px;
    -khtml-border-radius: 16px;
    border-radius: 24px;
    }
    #dologin
    {
    border: 2px solid #fff;
    -moz-border-radius: 12px;
    -webkit-border-radius: 12px;
    -khtml-border-radius: 12px;
    border-radius: 12px;
    }
    #cover
    {
    background: #000;
    height:100%;
    position:absolute;
    top: 0;
    left: 0;
    z-index: 90;
    }
    </style>
    <?php
    if (isset($_POST['submit']))
    {
    $player $_POST['player'];
    $number $_POST['number'];
    //echo $player.$number;
    if (($player !="Your Name" || $number !="Your Number")&&( $player !="" || $number !=""))
    {
    $message fopen("players.php","a");
    fwrite($message,"<br><span class=\"player\">".$player.": #".$number."</span><br>\n");
    fclose($message);
    }
    }
    ?>
    </head>
    <body><a href="#" onclick="showLogin();">Login</a><br>
    <h4>Heading here</h4>
    Some text here.
    <div id="cover"></div>
    <div id="mylogin" style="display:none">
    <fieldset id="dologin">
    <legend>Log in to the site.</legend>
    <form name="logmein" id="logmein" action="" method="post">
    <input type="text" name="player" value="Your Name"><br>
    <input type="text" name="number" value="Your Number">
    <input type="submit" name="submit" value="Enter Data">
    <input type="button" value="Exit" href="#" onclick="hideLogin();">
    </form></fieldset></div>
    <?php include('players.php'?>
    <script type="text/javascript"></script>
    </body>
    </html>
    Last edited by DrDOS; 11-15-2010 at 12:03 AM. Reason: Add PS

  • #4
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,916
    Thanks
    15
    Thanked 227 Times in 227 Posts
    Will this do for you? I updated my post above with the new code. It completely functions in the way you wanted, but it can be made much more sophisticated. Here is a link to the fopen function in PHP that might be useful.

    http://www.php.net/manual/en/function.fopen.php


  •  

    Posting Permissions

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