为了账号安全,请及时绑定邮箱和手机立即绑定

使用 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 关注
  • 70 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信