I have a test.php
where user is suppose to complete the form to update limit.
Upon submitting, the page will be redirected to example.php
where user will have to input one time password. If successful, page will redirect to doTest.php
where the limit is updated , if wrong OTP is input, user will have to complete the form again in test.php.
How do I redirect the page from test.php to example.php to doTest.php?
Note that: In my form on test.php
, the inputs will POST
to doTest.php
.
in test.php
<form method="POST" action="">
<table id="table">
<tr>
<td class="alt">Existing Daily Limit</td>
<td>S$ <?php echo $dailylimit; ?> </td>
<input type="hidden" name="dailylimit" value="<?php echo $dailylimit ?>"/>
</tr>
<tr>
<td class="alt"><label for="newdailylimit">New Daily Limit</label></td>
<td>$ <select name="newdailylimit">
<option value="100.00">100.00</option>
<option value="500.00">500.00</option>
<option value="1000.00">1000.00</option>
<option value="5000.00">5000.00</option>
</select></td>
</tr>
<tr>
<td class="alt">Amount Debited Today</td>
<td>S$ <?php echo $debited_today; ?></td>
</tr>
<tr>
<td class="alt">Amount Debited Left</td>
<td>S$ <?php echo ($dailylimit - $debited_today); ?> </td>
</tr>
</table>
<br/>
<input type="submit" name="submit" value="Submit">
</form>
in doTest.php,
<?php
if(isset($_POST['submit'])){
$dailylimit = $_POST['dailylimit'];
$newdailylimit = $_POST['newdailylimit'];
if ($dailylimit != $newdailylimit){
$query = "UPDATE user SET daily_limit='$newdailylimit' WHERE user_id='$user_id'";
$result = mysqli_query($link, $query) or die(mysqli_error($link));
echo "<script>alert('You have successfully updated your daily limit');</script>";
echo '<meta http-equiv="refresh" content="0">';
}
elseif ($dailylimit == $newdailylimit){
echo "<script>alert('You have selected the same daily limit as your previous one. Please choose a different one. ');</script>";
}
else{
}
}
?>
in example.php,
<center>
<form method="POST" action="" onSubmit="return validate(this)" >
<input type="button" value="Click for OTP" onclick="openotp()" /> <br/> <br/>
<table id="table">
<tr>
<td class="alt"><label for="otp">Enter the 6-digit iBanking OTP </label></td>
<td><input type="password" name="otp" maxlength="6"></td>
</tr>
</table>
<br/>
<input type="submit" name="submit" value="Click to submit OTP">
</form>
</center>
<?php
$user_id = $_SESSION['user_id'];
if(isset($_POST['submit'])){
$otp = $_POST['otp'];
$query = "SELECT otp FROM user where user_id='$user_id'";
$result = mysqli_query($link, $query) or die(mysqli_error($link));
$row = mysqli_fetch_array($result);
$rand = $row['otp'];
if ($otp == $rand) {
$query = "SELECT * FROM user WHERE user_id='$user_id' AND otp='$otp'";
$result = mysqli_query($link, $query) or die(mysqli_error($link));
echo "<script>location.href='doDailyLimit.php'</script>";
} else {
echo "<script>alert('You have keyed in an invalid OTP. Please try again.'); location.href='example.php';</script>";
}
}
?>