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
    New Coder
    Join Date
    Apr 2013
    Posts
    10
    Thanks
    8
    Thanked 0 Times in 0 Posts

    How do you make a form that stores data?

    How would I go about making an element on a website where the user can submit a string that is then stored somewhere as a variable that I can use in a JavaScript script?

    For example, I am working on a basic gambling game. You start off with $100, you make a bet, 50% chance of being doubled. I need a place where the user can enter their bet and I can then use what they entered as a variable. How would I do this?

    I know HTML, CSS, JavaScript, and I am working on learning PHP. Also, can I do this through my own computer as a local site and not one that is actually on the internet?


    Thank you

  • #2
    Regular Coder
    Join Date
    May 2011
    Posts
    124
    Thanks
    12
    Thanked 6 Times in 6 Posts
    You need to use PHP Sessions to temporarily store data.

    And as far as running locally you can, if you use WAMP, MAMP, or LAMP, depending upon your operating system. Are you looking to have other computers access the script too, or just the computer where the script is running?

    If you need other computers to access it, you're looking at an intranet website, and will need an in-house server. If it's just the computer itself running the script on its own box then WAMP, MAMP, or LAMP will do.

  • Users who have thanked HDRebel88 for this post:

    dekkahs (07-07-2013)

  • #3
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    Quote Originally Posted by HDRebel88 View Post
    You need to use PHP Sessions to temporarily store data.

    And as far as running locally you can, if you use WAMP, MAMP, or LAMP, depending upon your operating system. Are you looking to have other computers access the script too, or just the computer where the script is running?

    If you need other computers to access it, you're looking at an intranet website, and will need an in-house server. If it's just the computer itself running the script on its own box then WAMP, MAMP, or LAMP will do.
    Or a cookie !
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • Users who have thanked DrDOS for this post:

    dekkahs (07-07-2013)

  • #4
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Quote Originally Posted by HDRebel88 View Post
    You need to use PHP Sessions to temporarily store data.

    And as far as running locally you can, if you use WAMP, MAMP, or LAMP, depending upon your operating system. Are you looking to have other computers access the script too, or just the computer where the script is running?

    If you need other computers to access it, you're looking at an intranet website, and will need an in-house server. If it's just the computer itself running the script on its own box then WAMP, MAMP, or LAMP will do.
    To break it down further, if those acronyms (collectively known as XAMP) don't mean anything to you, they stand for Windows/Mac/Linux + Apache + MySQL + PHP. Basically, by installing one of those packages on your computer, you turn your computer into an open-source web server where you can test your websites locally. There are many tutorials online on installing XAMP.

    Using PHP, you can get the user's input from a simple form, like this:

    Code:
    <form name="" action="gameScript.php" method="post">
    <input type="text" name="bet" />
    <input type="submit" value="Place Bet!" name="submit" />
    </form>
    gameScript.php
    PHP Code:
    <?php
    $bet 
    $_POST['bet'];

    if( 
    is_numeric($bet) && $bet MAX && $bet 0)
    {
    //we're good!
    }
    else
    {
    //invalid value for $bet - handle errors here
    die();
    }

    ?>
    You get the form value through the $_GET or $_POST array, whichever you chose for the method property in the form tag. The key of the array for your value will be the name property of the input tag.
    Last edited by whizard; 07-07-2013 at 08:31 PM.
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • Users who have thanked whizard for this post:

    dekkahs (07-07-2013)


  •  

    Tags for this Thread

    Posting Permissions

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