I have files in a folder:
- view.php
- control.php
File view.php
has two submit buttons that post a value to control.php
.
When a user clicks one of submit buttons, it will
- The post value will be saved in array $questionTemp;
- Array $questionTemp will inserted into array $question, using array_push($question, $questionTemp)
- Then redirect a page to view.php
When a user clicks another submit button, it will
- pop array $question to array $result using $result = array_pop($question);
- echo the $result element
But I got nothing when try to echo $result (I think there's something when I redirect a page).
How do I this?!?!
view.php
<form action="control.php" method="post">
No
<input type="text" name="no" value="" /><br />
Question
<textarea name="question" rows="5" cols="20">
</textarea><br />
<input type="submit" value="Save" name="save" />
<input type="submit" value="Echo" name="echo" />
</form>
control.php
<?php
$question = array();
if(isset($_POST['save'])){
$questionTemp = array();
array_push($questionTemp, $_POST['no']);
array_push($questionTemp, $_POST['question']);
array_push($question, $questionTemp);
echo "<meta http-equiv=\"refresh\" content=\"0; URL=view.php \">";
}
if (isset($_POST['echo'])){
$result = array_pop($question);
echo $result[0];
echo $result[1];
}
?>