doutou7961 2017-11-17 21:09
浏览 67
已采纳

从两个PHP页面读取数据到第三页

I'm not able to combine the data from two pages. I'm only able to show data from one page. I tried searching for an explanation of my problem on google but I could not find it. I get an "Undefined index" error as you can see [![in this screenshot][1]][1]. Could not put just code over here because it keeps telling me that I need to use spacing with ctrl + K and im newbie in all this things so please forgive me..

<!DOCTYPE html>
<html>
<head>
<title>TEST</title>
</head>

<body>
 <form action = "page2.php" method = "POST">
                            <select list="Country" placeholder="Country" name="country" required class="form-control" style="max-width:250px; margin-top:50px;" id="Country">
                                <option >Bosnia & Herzegovina</option>
                                <option >Croatia</option>
                                <option >Serbia</option>
                                <option >England</option>
                                <option >Germany</option>
                                <option >Austria</option>
                                <option >Belgium</option>
                                <option >Switzerland</option>
                                <option >Italy</option>
                                <option >Romania</option>
                                <option >France</option>
                                <option >Montenegro</option>
                                <option >Slovenia</option>
                            </select>

            <input type="email" name="email" id="email" placeholder="Your email address" required class="form-control" style="max-width:250px;" />

            <input type="password" name="password" id="creapass" placeholder="Create your password" required  class="form-control" style="max-width:250px;" />

            <input type="password" name="password2" id="password" placeholder="Confirm your password" required  class="form-control" style="max-width:250px;" />

            <a href="page2.php"> <input type="button" value="Next" class="btn btn-primary" style="width:150px;"></a>

            </form>

</body>
</html>

Second Page

<!DOCTYPE html>
<html>
<head>
<title>test2</title>

</head>

<body>
<form action = "finalpage.php" method = "POST">

    <!-- Values from First Step -->

<input type="hidden" name="country" value="<?php $_POST['country'] ?>">

<input type="hidden" name="email" value="<?php $_POST['email'] ?>">

<input type="hidden" name="password" value="<?php $_POST['password'] ?>">
<input type="hidden" name="password" value="<?php $_POST['password2'] ?>">

<!-- End of Values from First Step -->

<?php
echo "Country:" .$_POST["country"]."</br>";
echo "Email:".$_POST["email"]."</br>";
echo "Password:".$_POST["password"]."</br>";
echo "Password2:".$_POST["password2"]."</br>";
?>


                                <input type="text" name="first" class="form-control" placeholder="First name" required style="max-width:250px;" >

                                <input type="text" name="last" class="form-control" placeholder="Last name" required style="max-width:250px;" />

                                <input type="date" name="date" class="dateb" id="dateOfBirth" required  />

                                        <select list="Country" placeholder="Country" name="country2" required class="form-control" style="max-width:250px; " id="Country">
                                            <option >Bosnian</option>
                                            <option >Croat</option>
                                            <option >Serb</option>
                                            <option >English</option>
                                            <option >German</option>
                                            <option >Austrian</option>
                                            <option >Belgian</option>
                                            <option >Swiss</option>
                                            <option >Italian</option>
                                            <option >Romanian</option>
                                            <option >French</option>
                                            <option >Montenegrin</option>
                                            <option >Slovenian</option>
                                        </select>

                                <input type="text" class="form-control" name="street1" placeholder="Street address 1" required style="max-width:250px;" />

                                <input type="text" class="form-control" name="street2" placeholder="Street address 2 (Optional)" style="max-width:250px;" />

                                <input type="text" class="form-control" name="city" placeholder="City" required style="max-width:250px;" />

                                <input type="text" class="form-control" name="region" placeholder="Province/Region" required style="max-width:250px;" />

                                <input type="text" class="form-control" name="postal" placeholder="Postal code" required style="max-width:250px;" />

                                <input type="tel" class="form-control" name="phone" placeholder="Phone number" required style="max-width:250px;" />

                                <input type="checkbox" name="terms" > I have read and agree to the Terms and WBC's User Agreement.

                                <a href="LinkCard.html"><input type="Submit" name="insert" value="Continue" class="btn btn-primary btn-lg"></a>


            </form>

</body>

</html>

Final Step.

<html>
<head>
<title>get data from another page</title>
</head>
<body>
<?php
echo "Country:" .$_POST["country"]."</br>";
echo "Email:".$_POST["email"]."</br>";
echo "Password:".$_POST["password"]."</br>";
echo "Password2:".$_POST["password2"]."</br>";

echo "First name:" .$_POST["first"]."</br>";
echo "Last name:".$_POST["last"]."</br>";
echo "Date:".$_POST["date"]."</br>";
echo "Country2:".$_POST["country2"]."</br>";
echo "Street1:" .$_POST["street1"]."</br>";
echo "Street2:".$_POST["street2"]."</br>";
echo "City:".$_POST["city"]."</br>";
echo "Region:".$_POST["region"]."</br>";
echo "Postal code:" .$_POST["postal"]."</br>";
echo "Phone number:".$_POST["phone"]."</br>";
?>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • doujupa7567 2017-11-17 21:25
    关注

    I am not copying the entire code of yours as it is not required. Below is the logic you have to follow.

    In the first step, i.e. your first form (I prefer using PHP format as it allows you to use PHP functions, if required), put your second PHP in the form's action.

    <form action = "step_2.php" method = "POST">
    

    Now in your step_2.php, you have to add the below in your form.

    <!-- Values from First Step -->
    
    <input type="country" name="country" value="<?php echo $_POST['country'] ?>">
    
    <input type="hidden" name="email" value="<?php echo $_POST['email'] ?>">
    
    <input type="hidden" name="password" value="<?php echo $_POST['password'] ?>">
    
    <!-- End of Values from First Step -->
    

    Above code will add the values posted from the first step into your second step form. Now you can simply fetch these values in the final step. To do this, add your final step PHP in your Action of this form.

    <form action = "final_step.php" method = "POST">
    

    In your final_step.php, you can normally get the values by $_POST.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记