Thread: Php form

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    42
    Rep Power
    2

    Php form


    1. file.php

    <html>
    <body>

    <?php
    session_start();

    $_SESSION['num1'] = mt_rand(1,5);
    $q1 = $_SESSION['num1'] ;
    echo "$q1";
    $_SESSION['num2'] = mt_rand(6,20);
    $q2 = $_SESSION['num2'] ;
    ?>

    <form name="lab5" method="post" action="f2.php">

    <table border=1 cellspacing=0 cellpading=0>

    <tr> <td> Q1 </td> <td> <?php echo $q1 ?> * <?php echo $q2 ?> </td> <td> <input type = 'text' size = '2' name = one > </td> </tr>

    <tr><td colspan=6 align='right'><input type='submit' value='Score' name='btn_score'></td></tr>


    </table>

    </form>

    </body>
    </html>

    2. f2.php

    <?php
    session_start();
    echo $_SESSION['num1'];
    echo $_SESSION['num2'];

    $UserV = $_POST['one'];

    echo "userValue is $UserV";

    $OneResult = $_SESSION['num1'] * $_SESSION['num2'] ;
    echo "result is $OneResult " ;

    ?>


    When i run file1.php, I get blank value for $userV after i enter a value.
    but i get correct value for $oneresult.

    How can i get the $UserV in f2 page?

    Please help.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    105
    Rep Power
    51
    You have no apostrophes around the name value of your field
    Code:
    <input type = 'text' size = '2' name = one >
    should be

    PHP Code:
    <input type='text' size='2' name='one' 
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    42
    Rep Power
    2
    Please disregard. I found my mistake.

    Thanks.

IMN logo majestic logo threadwatch logo seochat tools logo