0

I want to create a php multipage form, but i can't use $_SESSION variables to save and reuse data when i'm changing pages.

I've tought to use a personal global array (eg. GLOBAL $data; $data = array();) where i'll put my field variables, but when i go back through pages (eg. from pag 2 to pag 1), array $data is empty.

Where i've done wrong?

maures
  • 131
  • 1
  • 2
  • 13

2 Answers2

0

You can use variables by below ways:-

Global variables:-

$GLOBALS['variable'] = 'value';
// use them globally

Static variables:-

define('VARIABLE_NAME', 'value');
// static only. value is not changable

Session variables:-

session_start(); // need to define below line
$_SESSION['variable'] = 'value';

If you need to change variables value by page to page then you should use SESSION.

Check this link for GLOBAL variables.

Community
  • 1
  • 1
Ravi Hirani
  • 6,511
  • 1
  • 27
  • 42
-1

you have to use keyword GLOBAL while accessing data. for example on

page 1

$data = array("a", "b");

on page 2

global $data;
print_r($data);
Elixir Techne
  • 1,848
  • 15
  • 20