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

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

使用 IF 同時插入兩個表

使用 IF 同時插入兩個表

PHP
牧羊人nacy 2023-07-01 15:39:07
我試圖同時將數據插入兩個表中。第一個條件 IF 可以,但第二個條件 ELSE 不行。我在下面添加了我的插入代碼。我已經嘗試過使用 ELSE、ELSEIF 甚至 IF,但它不起作用。if (isset($_POST['save')) {    if (@$_POST['id_confrontations'] == "") {        @$description = $_POST['description'];        @$dt_confrontation = $_POST['dt_confrontation'];        @$id_competitions = $_POST['id_competitions'];        @$id_stages = $_POST['id_stages'];        @$score1 = $_POST['score1'];        @$score2 = $_POST['score2'];        @$mandant_club = $_POST['mandant_club'];        @$visitor club = $_POST['visitor_club'];        @$situation = $_POST['situation'];        @$phase = $_POST['phase'];        @$id_trainers = $_POST['id_trainers'];        @$history = $_POST['history'];        //saves the record in the "confrontations" table - In this case insertion is perfect        $confrontations = "INSERT INTO confrontations                             (description, dt_confrontation, id_competitions,                             stadiums_id, score1, scoring2, binder_club,                             situation, stage, id_trainers, history)                 VALUES ('$description','$dt_confrontation','$id_competitions',                        '$id_estadios','$score1','$score2',                        '$mandant_club','$visitor_club','$situation',                        '$stage','$id_trainers','$historia')';        //saves the record in the "panel" table - In IF insertion is perfect, but in ELSE it inserts as if it were IF        //In the IF rule the mandating_club would be == '1', so the GF would receive the score1 and the GC would receive the score2        //In the ELSE rule the visiting_club would be == '1', so the GC would receive the score1 and the GF would receive the score2感謝大家的關注和建議。
查看完整描述

1 回答

?
白衣非少年

TA貢獻1155條經驗 獲得超0個贊

您的代碼有大量錯誤數據和缺少變量

  1. 該變量@$visitorclub = $_POST['visitor_club']; 應該@$visitor_club

  2. 您聲明變量 @$history = $_POST['history']; 但是當將數據插入 [confrontations] 表時,您會調用 $historia 變量。

  3. 您以 ["] 雙引號開始將數據插入表 [confrontations],但以 ['] 單引號結束。

  4. 您的表 [對抗] 的插入代碼。您聲明 [11] 列名稱,但聲明 [12] 列值。因此,您現在應該將相同的列名稱和值添加到數據插入代碼中。

  5. 當您將數據插入[面板]表時,您的代碼如下

    插入面板(GF、GC、binant_club、visitor_club、id_competitions、狀態、狀態)

這里最后兩列(狀態,狀態)名稱相同。您不能使用相同的列名插入數據。

注意:如果你想用MySQL創建插入代碼。轉到 PHP MyAdmin 并選擇您的數據庫 >> 選擇您的表 >> 單擊插入 >> 插入虛擬數據 >> 現在 MySQL 為 PHP 生成自動插入代碼。使用此代碼通過更改列值插入數據。


查看完整回答
反對 回復 2023-07-01
  • 1 回答
  • 0 關注
  • 121 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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