使用PHP在多个页面上存储数据

芒果派

我正在基于博客模型构建业务规划师。但是,我无法在多个页面上执行此操作。在页面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>
SS

做这样的事情,而不是将数据插入数据库并更新到数据库中,而是将值存储在会话变量中,我的意思是

例子 :

$_SESSION["title"] = strip_tags($_POST['title']);

像这样将每个选项存储在会话变量中,直到到达最后一页。

终于在最后一页

将其插入数据库。像这样,

insert into table ('title',.....) values ($_SESSION["title"],....);

要跨多个页面传递数据时,请始终使用会话。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用PHP在多个页面上存储数据

来自分类Dev

在多个PHP页面上使用数组?

来自分类Dev

将用户输入存储在多个页面上

来自分类Dev

在多个PHP页面上为MySQL使用变量

来自分类Dev

在页面上显示本地存储数据

来自分类Dev

使用 PHP 在新页面上动态生成 SQL 数据

来自分类Dev

使用jquery在php的不同页面上打印数据

来自分类Dev

如何在多个页面上获取数据?

来自分类Dev

单个php页面上的多个sql查询

来自分类Dev

如何在php页面上显示存储在数据库中的图像?

来自分类Dev

使用JavaScript或jQuery存储在整个页面上持久存在的数据

来自分类Dev

使用BeautifulSoup在多个页面上编写循环

来自分类Dev

在多个页面上使用套接字

来自分类Dev

如何在多个页面上使用jQuery

来自分类Dev

从mysql检索数据并显示在php页面上

来自分类Dev

从mysql检索数据并显示在php页面上

来自分类Dev

使用php存储提交信息并在单独的html页面上显示

来自分类Dev

在单个页面上显示多个谷歌地图,其中包含来自 MySQL 的数据并使用循环

来自分类Dev

PHP会话将无法正常工作?在多个页面上使用变量

来自分类Dev

使用php ajax在同一页面上多个提交

来自分类Dev

使用PHP在Facebook页面上发布

来自分类Dev

PHP计算页面上使用代码的次数

来自分类Dev

使用php验证html页面上的字段

来自分类Dev

使用 ggplot 和 marrangeGrob 在多个页面上绘制多个图形

来自分类Dev

r 闪亮 - 在页面上显示多个数据表

来自分类Dev

PHP在多个页面上重定向用户

来自分类Dev

多个页面上的php会话变量不起作用

来自分类Dev

一个PHP页面上的多个mysqli删除代码

来自分类Dev

如何确定SSRS页面上使用的存储过程?

Related 相关文章

热门标签

归档