dongnan1899 2016-02-12 05:00
浏览 187
已采纳

如何在php中单击“保存”按钮后在会话中存储数据,并在单击“提交”按钮后提交数据

Hi how to save the data in session when we click on save button and need to submit the data in database when i click on submit button.Here is my form.

index.php

<form method="post" action="personal.php" id="myform">
<label>First Name</label>
<input type="text" name="first_name" value=""  />
<label>Last Name</label>
<input type="text" name="last_name" value=""  />
<button class = "medium" style="background-color: #2daebf;">Save</button>

Personal.php

$connection = mysql_connect("localhost", "root", "") or die(mysql_error());
$db = mysql_select_db("accountant", $connection);
$firstname = $_POST['first_name'];
$lastname=$_POST['last_name'];
$query=mysql_query("INSERT INTO table(first_name,last_name)values("$firstname","$lastname")");

How can i store these data into sessions and redirect to indexs.php and once i click on submit button total data needs to be inserted into database.

indexs.php

<form method="post" action="personals.php" id="myform">
<label>Address</label>
<input type="text" name="address" value=""  />
<label>Pincode</label>
<input type="text" name="pin" value=""  />
<button class = "medium" type="submit" style="background-color: #2daebf;">Save</button>

Personals.php

$connection = mysql_connect("localhost", "root", "") or die(mysql_error());
$db = mysql_select_db("accountant", $connection);
$address = $_POST['address'];
$pin=$_POST['pin'];
$query=mysql_query("INSERT INTO table(address,pin)values("$address","$pin")");
  • 写回答

2条回答 默认 最新

  • duande9301 2016-02-12 05:05
    关注

    This way you can save whole post data in php sessions.

    <?php
    session_start();
    
    $connection = mysql_connect("localhost", "root", "") or die(mysql_error());
    $db = mysql_select_db("accountant", $connection);
    
    if(isset($_POST) && !empty($_POST)){
    $address = $_POST['address'];
    $pin=$_POST['pin'];
    $query=mysql_query("INSERT INTO table(address,pin)values("$address","$pin")");
    
    //Session Work
    $_SESSION['form_data'] = $_POST;
    header ('location' : 'indexs.php');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵