use of session array
Results 1 to 4 of 4

Thread: use of session array

  1. #1
    Junior Member
    Join Date
    Apr 2012

    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" />
    PHP Code:
    if (isset(
    $_POST['Submit'])) {  
    $_SESSION['a'][0] = $_POST['type'];
    $_SESSION['a'][0]== 1000)
    "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
    Kansas City area
    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
    For debugging purposes, you can use something like the following to inspect what is in $_SESSION (or any other array):
    PHP Code:
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  4. #4
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    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];
    "The number is $b.";
    '$_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