www.webdeveloper.com
Results 1 to 7 of 7

Thread: session array for saving value of radion buttons

  1. #1
    Join Date
    Jun 2011
    Posts
    20

    Post session array for saving value of radion buttons

    <form method="post" action="point.php">
    <table bgcolor="#FFCC00" width="40" border="2" cellspacing="10">
    <tr><td colspan="20"><input type="radio" name="type" value="1000" />1000 point </tr>
    <tr><td colspan="20"><input type="radio" name="type" value="500" />500 point </tr>
    <tr><td colspan="2" align="center"><input type="submit" name="submit" id="submit" />
    </table>
    </form>

    <?php

    session_start();
    if (isset($_POST['Submit'])) {
    $_SESSION['a'][0] = $_POST['type'];
    if($_SESSION['a'][0]== 1000)
    { $b==1000;}
    else
    { $b==500;}
    echo"the no is ".$b;

    }


    ?>
    please check it that it is right. I want to save the value of radio button in a variable so that I may use it in further calculation.

  2. #2
    Join Date
    Jul 2009
    Location
    My house, sitting at the computer. Duh!
    Posts
    118
    Last I checked, session_start() needs to be called before anything is output, or you'll have errors. Basically you should be doing script work before putting any text or HTML on the page. This takes a little getting used to when coming from HTML coding, which has no separation of logic and display.

    PHP Code:
    <?php
    session_start
    ();

    // For all the variables you're using, not just one. This will help keep errors down.
    if (isset($_POST['submit'], $_POST['type']))
    {
        
    $type $_POST['type'];
        
    $_SESSION['a'][0] = (int)$type;
        
        if(
    $_SESSION['a'][0] == 1000)
            
    $b 1000;
        else
            
    $b 500;
    ?>

    <form method="post" action="point.php">
        <table bgcolor="#FFCC00" width="40" border="2" cellspacing="10">
            <tr><td colspan="20"><input type="radio" name="type" value="1000" />1000 point </tr>
            <tr><td colspan="20"><input type="radio" name="type" value="500" />500 point </tr>
            <tr><td colspan="2" align="center"><input type="submit" name="submit" id="submit" />
        </table>
    </form>

    <?php
    echo 'The number is '$b;
    ?>
    Last edited by ScottyBoy; 04-19-2012 at 10:27 AM.

  3. #3
    Join Date
    Nov 2006
    Location
    Oakland
    Posts
    500
    Error: if (isset($_POST['Submit'])) { }
    PHP is case sensitive. You do not have a field named 'Submit' but rather 'submit'

    session_start();

    if (isset($_POST['submit'])) {
    $_SESSION['a'][0] = $_POST['type'];

    $b=($_SESSION['a'][0]=='1000')?1000:500;

    echo"the no is ".$b;

    }

  4. #4
    Join Date
    Jul 2009
    Location
    My house, sitting at the computer. Duh!
    Posts
    118
    What he said. And you should also check all the post variables you're using, not just one.

  5. #5
    Join Date
    Jun 2011
    Posts
    20

    Post

    please guide me . what is meaning of ?1000 : 500
    if user clicks on radio button of value 1000 then value will be stored in variable b. if user clicks the radio button of value 500 then it will be stored in the same variable.

  6. #6
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by jamhussain View Post
    please guide me . what is meaning of ?1000 : 500
    if user clicks on radio button of value 1000 then value will be stored in variable b. if user clicks the radio button of value 500 then it will be stored in the same variable.
    That is a ternary operator. It is the short notation of an if/else statement
    PHP Code:
    $b=($_SESSION['a'][0]=='1000')?1000:500
    can be unfolded as:
    PHP Code:

    if($_SESSION['a'][0]=='1000'){
    $b=1000;
    }
    else{
    $b=500;


  7. #7
    Join Date
    Jun 2011
    Posts
    20

    Post

    If I use radio buttons
    two for physical coditions typical optimal


    two for point min max.
    and form is same.
    now this code is for one condition.
    now the values , we get are two ,and form is one.
    what should we do.
    thanks.

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