In my web system I have 3 files those are database.php , functions.php, dashboard.php
This is how my dashboard.php file looks like
<?php
$i = NULL;
if (isset($_POST['next'])) {
$i = getQuizes($i);
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input name="next" value="Next" type="submit">
</form>
functions.php is like below
function getQuizes($quizNo)
{
if($quizNo==NULL)
{
$quizNo=0;
}
include_once('database.php');
$sql = "SELECT * FROM quiz LIMIT ".$quizNo.",1";
$result = $conn->query($sql);
while($row=$result->fetch_assoc())
{
echo $row['question'],$quizNo;
}
$quizNo++;
return $quizNo;
}
when I clicked the submit button data go to the functions.php file and comes back to the dashboard.php then again $i becomes NULL. can I assign NULL only for first time.if yes,How can I do that.
store $i
in session and load it in every request, if it's not set in $_SESSION
set $i
to NULL
<?php
$i = isset($_SESSION['next']) ? $_SESSION['next'] : NULL;
if(isset($_POST['next']))
{
$i = getQuizes($i);
$_SESSION['next'] = $i;
}?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input name="next" value="Next" type="submit">
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With