首页 > 解决方案 > 如何使用redbean php将id从表单页面检索到另一个页面

问题描述

我正在使用 redbean php 创建一个表单。但是我在将 form.php 中的 id 传递给thankyou.php 时遇到了麻烦。客户提交表格后,我需要在感谢页面中显示总价。我不知道我的代码中缺少什么。请帮我。谢谢你。

表单.php

<?php

session_start();

require_once 'redbean_orm/rb.php';

$connection = new PDO('mysql:host=localhost;dbname=ocms','root','');

R::setup($connection);

$_SESSION["submit"] = '';

if(isset($_POST['submit']) && $_SERVER['REQUEST_METHOD'] === "POST") {

//create table and field 
$customerinfo = R::dispense('customer');
$customerinfo->name = $_POST['name']; 
$customerinfo->address = $_POST['address']; 
$customerinfo->price = $_POST['price'];
$id = R::store($customerinfo);?>

<html>
<body>
    <div class="container">
        <div class="row">
            <div class="col-md-8">
    <form action="" method="POST" id="contact-form">
        <div class="form-group">
            <label>Full Name</label>
            <input type="text" class="form-control" name="name" placeholder="Name" required>
        </div>
        <div class="form-group">
            <label>Address</label>
            <textarea type="text" class="form-control" name="address" placeholder="Address"></textarea>
            <!--<input type="text" class="form-control" name="address" placeholder="Address" required>-->
        </div>
        <div class="form-group">
            <label>Price</label>
            <input class="form-control" name="price" value="RM100.00" readonly="readonly" type="text" id="total">
        </div>
        <div class="form-group">
            <button class="btn btn-info" name="submit">
                <a href="thankyou.php?id=<?php echo $id;?>" 
                style="text-decoration: none;">Submit</a></button>
                <!--<?php echo R::load('users',$_POST['id']); ?>-->
        </div>
    </form>
</body>
</html>

谢谢你.php

<?php
session_start();

require_once 'redbean_orm/rb.php';

$connection = new PDO('mysql:host=localhost;dbname=ocms','root','');

R::setup($connection);

if (isset($_SESSION["submit"])) {

  $userinfo = R::load('users',$_GET['id']);
}
?>

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Thank You</title>
</head>

<body>

  <div class="jumbotron text-xs-center">
  <h1 class="display-3">Thank You For Your Request!</h1><br>
  <p class="lead"><strong>Your total charge :</strong><br>
    <?php 
    foreach (R::find('users') as $customer) {
      echo $customer = $_GET['id'].$customer['price'];
    }
    ?>
    <!--<input name="price" value="<?php echo $userinfo->price ?>" readonly="readonly" type="text">-->
  </p>
  <hr>
</div>
</body>

</html>

我熟悉 sql,但是当使用 redbean php 时,它很混乱。

标签: phpformsredbean

解决方案


对于正在寻找此解决方案的任何人。我自己找到了。我不应该在数据库中保存价格。只需存储在会话中并发送它thankyou.php。谢谢你看这里。解决方案:在帖子中,我$_SESSION['price'] = $_POST['price'];在thankyou.php中添加然后。我插入echo $_SESSION['price']


推荐阅读