Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 提交表格前包括一页_Php - Fatal编程技术网

Php 提交表格前包括一页

Php 提交表格前包括一页,php,Php,我有一个test.php,用户应该在这里填写表单以更新限制。 提交后,页面将重定向到example.php,用户必须在其中输入一次性密码。如果成功,页面将重定向到doTest.php更新限制,如果输入了错误的OTP,用户将不得不在test.php中再次填写表单 如何将页面从test.php重定向到example.php再重定向到doTest.php? 注意:在我的test.php表单中,输入将POST发送到doTest.php 在test.php中 <form me

我有一个
test.php
,用户应该在这里填写表单以更新限制。 提交后,页面将重定向到
example.php
,用户必须在其中输入一次性密码。如果成功,页面将重定向到
doTest.php
更新限制,如果输入了错误的OTP,用户将不得不在test.php中再次填写表单

如何将页面从test.php重定向到example.php再重定向到doTest.php?

注意:在我的
test.php
表单中,输入将
POST
发送到
doTest.php

在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>

现行每日限额
新加坡元

$\u会话中保存数据
,使用
标题('Location:next page.php')
,转到下一页检查密码,如果密码正确且会话数据可用,则保存数据,否则清除会话并重定向到第一页。

首先在test.php中的会话中保存数据。只有在检查otp是否正确后,才能将它们添加到数据库中

在test.php的开头添加以下代码并设置action=“test.php”

这样,您就不需要第三个文件

if(isset($_POST['submit'])){ //form has been submitted
    if($_POST['dailylimit'] == $_POST['newdailylimit']){
        echo "<script>alert('You have selected the same daily limit as your previous one. Please choose a different one. ');</script>";
    } else {
        //you can store 'dailylimit' the same way, but i suppose you won't be needing it anymore.
        $_SESSION['newdailylimit'] = $_POST['newdailylimit'];
        header("Location : example.php"); //this will take you to example.php
    }
}
if(isset($\u POST['submit']){//表单已提交
如果($\U POST['dailylimit']=$\U POST['newdailylimit'])){
echo“警报('您已选择与上一个相同的每日限额。请选择其他限额');”;
}否则{
//你可以用同样的方式储存“dailylimit”,但我想你不再需要它了。
$\会话['newdailylimit']=$\发布['newdailylimit'];
header(“Location:example.php”);//这将带您到example.php
}
}
在example.php中,您需要检查otp是否正确。因此,设置action=“example.php”并将以下代码添加到example.php的开头

if(isset($_POST['submit'])){  // form has been submitted.
    $otp = $_POST['otp'];
    //now check $otp against your database to see if its correct.
    //your database code goes here.
    if(//otp is right ){
        $newdailylimit = $_SESSION['newdailylimit'];  //it was stored in test.php
        //similarly store your user_id from session.
        //insert newdailylimit into database.
    } else { // which means otp is wrong
        header("Location : test.php?otp=0");
        /* by seding otp=0 you can let the user in test.php know that you were redirected back because your otp was wrong.
        you can add the following code in the beginning of test.php , which will show the message that otp was wrong.
        and they have to go through the whole process again.

        if(isset($_GET['otp'])){
            if($_GET['otp']==0){
                echo "<script>alert('You have provided wrong otp. blah bla...');</script>";
            }
        }
        */
    }
}
if(isset($\u POST['submit']){//表单已提交。
$otp=$_POST['otp'];
//现在对照数据库检查$otp,看看它是否正确。
//你的数据库代码在这里。
如果(//otp是正确的){
$newdailylimit=$\u会话['newdailylimit'];//它存储在test.php中
//同样,存储会话中的用户id。
//将newdailylimit插入数据库。
}否则{//这意味着otp是错误的
标题(“位置:test.php?otp=0”);
/*通过设置otp=0,您可以让test.php中的用户知道您被重定向回了,因为您的otp是错误的。
您可以在test.php的开头添加以下代码,这将显示otp错误的消息。
他们必须再次经历整个过程。
如果(isset($_GET['otp'])){
如果($_GET['otp']==0){
echo“警报('您提供了错误的otp.blah bla…');”;
}
}
*/
}
}

如何在$\u会话中保存数据?我应该在哪里插入标题('Location:next page.php')?这是您的脚本吗?我看到您已经在使用会话中的数据。php是一个通用名称。您需要使用页面名称。因此,我应该将表单值存储在session>上,而不是使用POST。有太多的事情需要解释。。很抱歉了解如何在会话中存储数据
if(isset($_POST['submit'])){ //form has been submitted
    if($_POST['dailylimit'] == $_POST['newdailylimit']){
        echo "<script>alert('You have selected the same daily limit as your previous one. Please choose a different one. ');</script>";
    } else {
        //you can store 'dailylimit' the same way, but i suppose you won't be needing it anymore.
        $_SESSION['newdailylimit'] = $_POST['newdailylimit'];
        header("Location : example.php"); //this will take you to example.php
    }
}
if(isset($_POST['submit'])){  // form has been submitted.
    $otp = $_POST['otp'];
    //now check $otp against your database to see if its correct.
    //your database code goes here.
    if(//otp is right ){
        $newdailylimit = $_SESSION['newdailylimit'];  //it was stored in test.php
        //similarly store your user_id from session.
        //insert newdailylimit into database.
    } else { // which means otp is wrong
        header("Location : test.php?otp=0");
        /* by seding otp=0 you can let the user in test.php know that you were redirected back because your otp was wrong.
        you can add the following code in the beginning of test.php , which will show the message that otp was wrong.
        and they have to go through the whole process again.

        if(isset($_GET['otp'])){
            if($_GET['otp']==0){
                echo "<script>alert('You have provided wrong otp. blah bla...');</script>";
            }
        }
        */
    }
}