php - global array gets overwritten -


i guide website's users through 2 step selection html select elements displayed 1 after other. first 1 used choose trainer , second 1 used choose monster. after one, want display battle-screen information on trainer , monster. therefore want store information in global array. tried use post array, gets overwritten once include battle-content.

on little project use config.php file included via

require_once('config.php'); 

it includes functions.php. in config file declare array this:

$wahl = array('trainer' => 'test', 'monster' => 'test' ); 

now in function write new index of array:

function trainernamebelegen($t) {  global $con;  global $wahl;  $sql = "select * `trainer` t_id = '".$t."'";  $result = mysqli_query($con, $sql);  $row = mysqli_fetch_array($result);  $wahl['trainer'] = $row['name'];   echo $wahl['trainer'];  } 

this executed after first selection , works fine. tested echoing array , got value expected.

after second selection though, array get's overwritten , shows "test" , "test" again.

this content part of index.php

<?php require_once( 'config.php'); if (isset($_post['s_tselect'])) {trainernamebelegen($_post['trainerwahl']);} if (!isset($_post['monsterauswahl'])) {require_once('startseite.php');}   else {require_once('battle.php');} ?> 

it first requires config.php, checks if trainer has been selected , if calls function put's trainer's name global array. if no monster has been chosen, startseite.php (with selectors) shown - else battle screen.

any appreciated!


Comments