【问题标题】:how to retrieve id from form page to another page using redbean php如何使用redbean php将id从表单页面检索到另一个页面
【发布时间】:2019-07-31 05:11:39
【问题描述】:

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

form.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 时它很混乱。

【问题讨论】:

    标签: php forms redbean


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-09-26
      • 2019-03-06
      • 2012-09-17
      • 1970-01-01
      • 1970-01-01
      • 2017-05-22
      • 2016-12-24
      相关资源
      最近更新 更多