亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從一個表中獲取值并將相同的值插入到另一表中

如何從一個表中獲取值并將相同的值插入到另一表中

PHP
慕娘9325324 2023-10-21 16:15:36
我在同一頁面中使用兩個按鈕“獲取”和“提交”。當我單擊“獲取”按鈕時,我從一個表 [ticket Generation] 獲取值并顯示在表單中,并且獲取工作正常。當我嘗試將獲取記錄插入另一個表[詳細信息]時,記錄未插入。HTML PART<div class="col-sm-3">             <center><input type="submit" name="fetch" id="fetch" class="btn btn-primary" value="Fetch Records" style="padding: 4px 10px 4px 10px;float:right;"></center>        </div>         <div class="col-sm-3">                <center><input type="submit" name="submit" id="submit" class="btn btn-primary" value="Submit" style="padding: 4px 10px 4px 10px;float:left;"></center>        </div>PHP PARTif (isset($_POST['fetch'])) {       $ticketid1 = $_POST['tid'];        $sel = "select * from ticketgeneration where ticket_id='$ticketid1'";        $res = mysqli_query($conn,$sel);        $row = mysqli_fetch_array($res);            }上面的代碼從“ticket Generation”表中獲取值并顯示在文本框中<input type="text" class="form-control" name="custname" id="custname" value="<?php echo $row['customer_name'];?>">當我嘗試將獲取的值插入其他表[詳細信息]時,它沒有插入。if(isset($_POST['submit'])) {        $ticketgendate = $_POST['date'];       $ticketid = $row['ticket_id'];        $customername = $row['customer_name'];...$ins = "insert into details (date,ticket_id,customer_name,...)values (('$ticketgendate','$ticketid','$customername',...)";$res = mysqli_query($conn,$ins);我是否在某處缺少條件...
查看完整描述

2 回答

?
叮當貓咪

TA貢獻1776條經驗 獲得超12個贊

從一個表到另一表的任何數據插入都使用此查詢。

$query = 'insert into table_name (col1, col2, columnList....) select col1, col2, columnList... from table_name where ticket_id = $id';

您可以在 select 語句中添加其他列,只需在 insert 查詢語句中提及列名即可。

謝謝!??!


查看完整回答
反對 回復 2023-10-21
?
12345678_0001

TA貢獻1802條經驗 獲得超5個贊

您需要使用以下查詢在您的案例中插入數據。僅使用 $ticketid1 插入數據。

$ins = "insert into details (date,ticket_id,customer_name,...) select date,ticket_id,customer_name,... from ticketgeneration where ticket_id='$ticketid1'";

然后運行您的查詢,它將直接插入選定的數據,而不需要執行額外的代碼。


查看完整回答
反對 回復 2023-10-21
  • 2 回答
  • 0 關注
  • 137 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號