php - 如何使用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 时,它很混乱。
解决方案
对于正在寻找此解决方案的任何人。我自己找到了。我不应该在数据库中保存价格。只需存储在会话中并发送它thankyou.php。谢谢你看这里。解决方案:在帖子中,我$_SESSION['price'] = $_POST['price'];
在thankyou.php中添加然后。我插入echo $_SESSION['price']
。
推荐阅读
- python - 当我尝试运行 python manage.py runserver 时出现“服务器错误,请联系管理员”
- java - 即使设置了 spring.expression.compiler.mode,Spring SpEL 也不会编译
- r - 端口转发的 Docker 和 Plumber 问题
- html - 在某些情况下不显示离子图标
- r - 将字符数据转换为日期——COVID 19 研究
- typescript - 应用程序中的 Ionic 5 白色 iframe,但在网络上工作
- java - Java NIO - 消息的累积
- jquery - 如何从剑道网格表头中删除文本?
- javascript - 二次产量在 JavaScript 生成器函数中不起作用
- amazon-web-services - 如何从登录的 amazon connect 获取代理电子邮件地址