使用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 条评论
登录 后参与评论

相关文章