douxiao0400 2018-08-15 23:20
浏览 29

PHP加载数据,按按钮将加载数据插入另一个表

I have the following code in load.php to load data into some form fields

<?php
// initalize the variables 
$user_id   = "";
$firstname = "";
$lastname  = "";
$picture   = "";
$reg_date   = "";

// php code to search data in mysql database and set it in input text
if(isset($_POST['search']))
{
    // connect to mysql
    $dbc = mysqli_connect("127.0.0.1", "hello", "world","demodb");

    // id to search
    $user_id = mysqli_real_escape_string($dbc, $_POST['user_id']);

    $query = "SELECT * FROM Users WHERE user_id = '$user_id' LIMIT 1";
    $rs    = mysqli_query($dbc, $query);
    if (mysqli_num_rows($rs) == 1)
    {
      $row       = mysqli_fetch_array($rs);
      $user_id      = $row['user_id'];
      $firstname = $row['firstname'];
      $lastname  = $row['lastname'];
      $picture     = $row['picture'];
      $reg_date     = $row['reg_date'];
    }


    else
    {
      echo "Undefined ID";
    }

}
?>

The fields look like this, in the first field the user puts their user ID and presses enter or the FIND button and than the data is populated in the First Name and Last Name field.

   <form method="post">

    <div class="wrap-input1 validate-input" data-validate = "SCAN ID TO SEARCH">
    <input class="input1" type="text" name="user_id" placeholder="SCAN ID TO SEARCH" autofocus>
    <span class="shadow-input1"></span>
</div>  


    <div class="wrap-input1 validate-input" >
    <input class="input1" type="text" name="firstname" placeholder="First Name"  value="<?= htmlspecialchars($firstname) ?>">
    <span class="shadow-input1"></span>
</div>


    <div class="wrap-input1 validate-input" >
    <input class="input1" type="text" name="lastname" placeholder="Last Name"  value="<?= htmlspecialchars($lastname) ?>">
    <span class="shadow-input1"></span>
</div>


      <input type="submit" name="search" value="Find" class="btn btn-primary btn-lg btn-block" >

Now, when the data is loaded, I want to have another button in which the user will press and it should take the data that was already populated like the 'First Name' and 'Last Name' into another MySQL table. For example, I would like another button like this:

<input type="submit" value="Clock IN" name="clock" class="btn btn-success btn-lg btn-block" />

When pressed, I want to Insert data into another table called timeclock. Example,

INSERT INTO `timeclock` (`user_id`, `firstname`, `lastname`, `status`, `startTime`) VALUES
('$user_id', '$firstname', '$lastname', 'Clock IN', now());

How should I modify my load.php and buttons to accomplish this?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化