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 7 of 7

Thread: Form question

  1. #1
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Form question

    I want to have a value, starting at zero, so if radio button value="B" id="one" is checked then the value goes up one, how can this be done?

  • #2
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Please could you give some more info! Do you want the value to be saved on the server? Do you want it in a textfile or DB, or a session?

  • #3
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    A text file, let's call it saveto.txt here (another part of the script will control that).

  • #4
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try something along the lines of:

    PHP Code:
    <?php

    $file 
    "saveto.txt";

    $fp fopen($file'r');

    while(!
    feof($fp)){
       
    $str_val fgets($fp32); // not expecting the file do contain more than 32 bytes (32 digit number)
    }

    fclose($fp);

    settype($str_val'int');

    if(
    $_POST['one'] == 'B'){

       
    $str_val++;
       
    $fw fopen($file'w');
       
    fputs($fw$str_val);
       
    fclose($fw);


    }

    ?>

  • #5
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    What is that w, r and int for?

  • #6
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    r and w are file handling modes, see http://www.php.net/fopen. int tells the script to make sure the result is an integer, so we can preform mathmatical operations on it (see http://www.php.net/settype)

  • #7
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    What does it put in the document?


  •  

    Posting Permissions

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