This question will probably be marked as duplicate, but I didnt find other answers helpful.
I am creating a site where user could answer multiple type of questions. Thus i wrote code so the corresponding html template will appear, according to type of question. Right now my php code is following:
<?php
include_once 'init/init.funcs.php';
$_SESSION['pollid']=(int) $_GET['pollid'];
$questions = array();
$answer = $_POST['answer'];
if (!isset($_SESSION['answering'])) {
$result = mysql_query('SELECT * from katse_kysimused where kysimustik_id="' . $_SESSION['pollid'] . '"');
while($row = mysql_fetch_assoc($result)) {
$questions[] = $row['kysimus'];
}
$_SESSION['answering']['questions'] = $questions;
$_SESSION['answering']['index'] = 0;
}
$x = $_SESSION['answering']['index'];
$result3 = mysql_query('SELECT tyyp_id FROM katse_kysimused where kysimus= "' . $_SESSION['answering']['questions'][$x] . '"');
$type = mysql_result($result3, 0);
if ($type=='3'){
echo $_SESSION['answering']['questions'][$x];
$result4 = mysql_query('SELECT kysimus_id FROM katse_kysimused where kysimus= "' . $_SESSION['answering']['questions'][$x] . '"');
$question_id = mysql_result($result4, 0);
$result5 = mysql_query('SELECT * from katse_valik_vastused where kysimus_id="' . $question_id . '"');
if($result5 === FALSE) {
die(mysql_error());
}
while($row = mysql_fetch_assoc($result5)) {
$options[] = $row['vasuts'];
}
foreach($options as $option=>$option_value) {
echo $option_value;
}
}
if ($type=='1'){
echo "<meta http-equiv='refresh' content='0;url=http://localhost/Praks/tekstkysimusele_vastamine2.php'>";
}
if(isset($_POST['submit'])){
$result2 = mysql_query('SELECT kysimus_id FROM katse_kysimused where kysimus= "' . $_SESSION['answering']['questions'][$x -1] . '"');
$q_id = mysql_result($result2, 0);
mysql_query('INSERT INTO katse_vastused2 (id, vastus,kysimus_id, vastustik_id) VALUES (NULL,"' . $answer . '","' . $q_id . '","1")');
}
$_SESSION['answering']['index']++;
?>
And what I want to do is to make following html template appear, when $type=='1'.
<?php
echo $_SESSION['answering']['questions'][$x];
?>
<html>
<br>
<form method="post" action="answering.php">
<input type="text" name="answer" style="width:300px; height:150px;"><br>
<input name= "submit" type="submit" value="Vasta">
</form>
</html>
My question is, how could I make it appear with question. Right now $_SESSION['answering']['questions'][$x]; is undefined.How could I transfer it from first file to second?