use of session array
Results 1 to 4 of 4

Thread: use of session array

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    21

    Post use of session array

    HTML Code:
    <form method="post" action="ecc.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 Code:
    <?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.
    Last edited by bradgrafelman; 04-18-2012 at 01:49 PM. Reason: bbcode tags added

  2. #2
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,429
    When posting HTML or PHP code, please use the board's [html]..[/html] or [php]..[/php] bbcode tags (respectively) as they make your code much easier to read and analyze.

    Quote Originally Posted by jamhussain View Post
    please check it that it is right.
    Why? Isn't that your job?

    If something isn't working or you're getting errors, then you should say so or at least ask a specific question.
    Last edited by bradgrafelman; 04-18-2012 at 01:50 PM.

  3. #3
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    13,943
    For debugging purposes, you can use something like the following to inspect what is in $_SESSION (or any other array):
    PHP Code:
    die("<pre>".print_r($_SESSIONtrue)."</pre>"); 
    Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." ~ from Nation, by Terry Pratchett

    "But the main reason that any programmer learning any new language thinks the new language is SO much better than the old one is because he’s a better programmer now!" ~ http://www.oreillynet.com/ruby/blog/...ck_to_p_1.html


    eBookworm.us

  4. #4
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    Location
    so.Cal
    Posts
    949
    It would be better to do your validation before you save the value to the session. That way, you don't have to check it every time you use it, and you're less likely to forget.
    PHP Code:
    // define valid options
    $valid = array( 1000,500 );

    // make sure the submitted value is valid
    if( in_array$valid,$_POST['type'] ) ){
        
    // save it to your session
        
    $_SESSION['a'][0] = $_POST['type'];
    }

    // later ...
    if( !empty( $_SESSION['a'][0] ) ){
        
    $b $_SESSION['a'][0];
        print 
    "The number is $b.";
    }else{
        print 
    '$_SESSION[a][0] was empty.';


Thread Information

Users Browsing this Thread

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

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
  •