Passing PHP Variable From One Dynamic Page to Another

后端 未结 2 1288
-上瘾入骨i
-上瘾入骨i 2021-01-28 12:09

I am trying to pass on some variables using SESSION from one PHP page to the next.

The first page contains this code and after the user clicks submit, it goes to Page 2:

相关标签:
2条回答
  • 2021-01-28 12:50

    Make sure that you are starting your session before creating the variables and before calling them back :

    session_start();
    
    0 讨论(0)
  • 2021-01-28 12:55

    Are you sure your variables are set i.e. $totalcost? A comment on your code. Unless, you are breaking in and out of PHP and HTML, you do not need to open and close PHP on every line.

    This can be rewritten:

    <!--SESSIONS TO PASS ON VARIABLES-->
    <?php $_SESSION['file'] = $file; ?>
    <?php $_SESSION['linecount'] = $linecount; ?>
    <?php $_SESSION['priceperpost'] = $priceperpost; ?>
    <?php $_SESSION['totalcost'] = $totalcost; ?>
    <!--//SESSIONS TO PASS ON VARIABLES-->
    

    As:

    <?php
    // SESSIONS TO PASS ON VARIABLES
    session_start();
    $_SESSION['file'] = $file;
    $_SESSION['linecount'] = $linecount;
    $_SESSION['priceperpost'] = $priceperpost;
    $_SESSION['totalcost'] = $totalcost; 
    // SESSIONS TO PASS ON VARIABLES
    ?>
    
    0 讨论(0)
提交回复
热议问题