我正在建立一个基于博客模型的商业策划者。但是我不能在多个页面上这样做。在第1页,当用户点击“下一步”时,就像点击“发布”一样。数据被存储并添加到其他业务计划或“帖子”的列表中。在第一页中,数据通过“插入”存储到数据库中来存储。我想也许我可以简单地“更新”第2页的数据库,依此类推,以消除多个列出的“帖子”或商业计划。数据存储在第一页,而不是第二页。如果我使用“INSERT INTO ...”添加每个页面的数据,但每个页面都是作为单独的商业计划或多个帖子收集的。任何建议都表示赞赏。
这是第1页:
<?php
session_start();
include_once("db.php");
if(isset($_POST['post'])) {
$title = strip_tags($_POST['title']);
$compName = strip_tags($_POST['compName']);
$createdBy = strip_tags($_POST['createdBy']);
$phone = strip_tags($_POST['phone']);
$title = mysqli_real_escape_string($db,$title);
$compName = mysqli_real_escape_string($db,$compName);
$createdBy = mysqli_real_escape_string($db,$createdBy);
$phone = mysqli_real_escape_string($db,$phone);
$date = date('l jS \of F Y h:i A');
$sql = "INSERT INTO plans (title, date, compName, createdBy, phone) VALUES('$title', '$date', '$compName', '$createdBy', '$phone')";
mysqli_query($db, $sql);
header("Location: post2.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<div class="container">
<head>
<title>Create Business Plan</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<h2>Create a new business plan</h2>
<form action="post1.php" method="post" enctype="multipart/form-data">
<br /><br />
<p>Plan Title: <input name="title" type="text" autofocus size="48"></p>
<p>Company Name: <input name="compName" type="text" autofocus size="48"></p>
<p>Business Type: <input placeholder="Ie. Inc. (USA) or Oy (Finland)" name="bizType" type="text" autofocus size="48"></p>
<p>Created By: <input name="createdBy" type="text" autofocus size="48"></p>
<p>Phone: <input name="phone" type="text" autofocus size="48"></p>
<br /><br />
<form action="<?php 'post2.php=?pid=$id'; ?>">
<input name="post" type="submit" value="Next">
</form>
<br /><br />
</form>
</body>
</div>
</html>
这是第2页:
<?php
session_start();
include_once("db.php");
if(isset($_POST['post'])) {
$marketPlan = strip_tags($_POST['marketPlan']);
$economics = strip_tags($_POST['economics']);
$products = strip_tags($_POST['products']);
$customers = strip_tags($_POST['customers']);
$marketPlan = mysqli_real_escape_string($db,$marketPlan);
$economics = mysqli_real_escape_string($db,$economics);
$products = mysqli_real_escape_string($db,$products);
$customers = mysqli_real_escape_string($db,$customers);
$date = date('l jS \of F Y h:i A');
$sql = "UPDATE plans SET marketPlan='$marketPlan', economics='$economics', products='$products', customers='$customers' WHERE id=$pid";
mysqli_query($db, $sql);
header("Location: post3.php"); //CHANGE LOCATION FOR NEXT PAGE
}
?>
<!DOCTYPE html>
<html lang="en">
<div class="container">
<head>
<title>Create Business Plan</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<h2>The Marketing Plan</h2>
<form action="post2.php" method="post" enctype="multipart/form-data">
<br /><br />
<h4>Market Research</h4>
<p>The marketing plan requires intensive research for the type of industry your business wants to enter. It is very dangerous to assume that you are already well informed about your intended market. Market research is vital to make sure you are up to date. Use the business planning process as your opportunity to uncover data and to question your marketing efforts.</p>
<textarea name="marketPlan" rows="15" cols="100"></textarea></p><hr />
<h4>Economics</h4>
<p>What is the total size of your market? What percent of market share will you have? (This is important only if you think you will be a major factor in the market.) What is currently in demand in your target market? What are the trends in target market—growth, consumer preferences, and in product development? Growth potential and opportunity for a business of your size.
<textarea name="economics" rows="15" cols="100"></textarea><hr />
<h4>Products</h4>
<p>In the <i>Products and Services</i> section, you described your products and services from your point of view. Now describe them from how your customers see them.</p><br /><textarea name="products" rows="15" cols="100"></textarea></p><hr />
<h4>Customers</h4>
<p>Identify your targeted customers, their characteristics, and their geographical location. This is known as customer demographics.</p>
<textarea name="customers" rows="15" cols="100"></textarea></p>
<input name="post" type="submit" value="Next">
</form>
</body>
</div>
</html>
答案 0 :(得分:1)
做这样的事情,而不是将数据插入和更新到数据库,将值存储在会话变量中,我的意思是
示例:
$_SESSION["title"] = strip_tags($_POST['title']);
在会话变量中存储每个选项,直到您到达最后一页。
最后在最后一页
将其插入数据库。像这样,
insert into table ('title',.....) values ($_SESSION["title"],....);
当您想要跨多个页面传递数据时,始终使用会话。
答案 1 :(得分:0)
我认为你只做对了。第一篇文章必须在表格中插入这些细节,下一篇文章更新你想要更新的字段。
答案 2 :(得分:0)
在第二页中,您必须从您的网址获取ID
if (isset($_GET['pid']))
$pid = $_GET['pid'];
当您尝试更新未定义的ID时
答案 3 :(得分:0)
您必须将新创建的记录的ID传递给下一页;最安全的方法可能是将它存储在会话中。因此,在第一页上,更改此内容:
mysqli_query($db, $sql);
到
$query = mysqli_query($db, $sql);
$_SESSION['new_plan_id'] = $query->insert_id;
然后,在您的第二页中再次查询ID
if (isset($_SESSION['new_plan_id']))
{
$pid = $_SESSION['new_plan_id'];
}
else
{
die('No valid session');
}
用户完成计划后,从会话中删除new_plan_id
。您可能还想将session_start()添加到全局包含,因此始终启用它。