[英]How to Fetch value from another table and INSERT the same data to specific row in a different table
I am seeking help on how to use data fetched from a different table and INSERT the same data to a DIFFERENT table while specifying the row which data will be stored considering the session created.我正在寻求有关如何使用从不同表获取的数据并将相同数据插入到不同表中的帮助,同时指定考虑创建的会话将存储哪些数据的行。
if (isset($_GET['apply'])) {
$sess_id = $_SESSION['t_user_id'];
if (isset($_SESSION['UserName']) && $_SESSION['UserName'] == true) {
$query = "SELECT * FROM users";
$select_posts = mysqli_query($connection, $query);
while ($row = mysqli_fetch_assoc($select_posts))
{
$ID = $row['ID'];
}
$query = "INSERT INTO users(commission)
SELECT cost
FROM `tbl_jobs`
WHERE ID = '$sess_id' ";
$update_user_role = mysqli_query($connection,$query);
if (!$update_user_role) {
die("QUERY FAILED" . mysqli_error($connection,$query));
}
header("Location: admin.php");
}
}
Currently its fetching the data from different table and posting to unintended row as per session.目前它从不同的表中获取数据并根据会话发布到意外的行。
I will like to see the data fetched from the different table being posted to row which is equal to username session created.我希望看到从不同表中获取的数据被发布到与创建的用户名会话相同的行。
I think you want update
:我想你想要
update
:
update users u join
tbl_jobs j
on u.id = j.user_id -- guessing at the `JOIN` condition here
set commission = j
where u.id = ?;
Also note the use of ?
还要注意使用
?
. . This is a parameter placeholder -- and an indication that you should be using parameters rather than munging query strings.
这是一个参数占位符——并且表明您应该使用参数而不是修改查询字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.