记录没有被编写或被删除在父桌上,我不知道为什么使用Mariadb/MySQL和PHP。想法?

发布于 2025-02-08 02:23:41 字数 4337 浏览 2 评论 0原文

这是Quesiton中数据库表的结构。

官员:

CREATE TABLE IF NOT EXISTS `officials` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `last` varchar(250) NOT NULL DEFAULT '',
  `first` varchar(250) NOT NULL DEFAULT '',
  `middle` varchar(250) NOT NULL DEFAULT '',
  `address` varchar(250) NOT NULL DEFAULT '',
  `city` varchar(250) NOT NULL DEFAULT '',
  `state` varchar(250) NOT NULL DEFAULT '',
  `zip` varchar(250) NOT NULL DEFAULT '',
  `homeph` varchar(250) NOT NULL DEFAULT '',
  `workph` varchar(250) NOT NULL DEFAULT '',
  `cellph` varchar(250) NOT NULL DEFAULT '',
  `main_phone` varchar(10) DEFAULT NULL,
  `email` varchar(250) NOT NULL DEFAULT '',
  `notes` text NOT NULL,
  `blockreg` varchar(10) NOT NULL,
  `inactive` varchar(10) NOT NULL,
  `gender` varchar(100) NOT NULL,
  `minority` varchar(100) NOT NULL,
  `affiliate` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Is affiliate official? 0 = no. 1 = yes.',
  PRIMARY KEY (`id`),
  UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=14506 DEFAULT CHARSET=latin1;

交易(从原始帖子编辑到显示外国密钥约束):

CREATE TABLE IF NOT EXISTS `transactions` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `offid` int(11) NOT NULL,
  `txn_id` varchar(64) NOT NULL,
  `txn_time` varchar(24) NOT NULL,
  `approval_code` varchar(24) DEFAULT NULL,
  `amount` varchar(8) NOT NULL,
  `result_message` varchar(100) NOT NULL,
  `ch_phone` varchar(10) NOT NULL COMMENT,
  `ch_card_type` varchar(4) NOT NULL,
  `ch_address` varchar(50) NOT NULL,
  `ch_state` varchar(15) NOT NULL,
  `ch_last_name` varchar(50) NOT NULL,
  `ch_email` varchar(100) NOT NULL,
  `ch_zip` varchar(10) NOT NULL,
  `ch_exp_date` varchar(4) NOT NULL,
  `ch_city` varchar(50) NOT NULL,
  `ch_first_name` varchar(30) NOT NULL,
  `ch_transaction_type` varchar(15) NOT NULL,
  `ch_card_number` varchar(18) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `txn_id` (`txn_id`) USING BTREE,
  KEY `offid` (`offid`)
) ENGINE=InnoDB AUTO_INCREMENT=72 DEFAULT CHARSET=utf8mb4;

ALTER TABLE `transactions`
  ADD CONSTRAINT `transactions_ibfk_1` FOREIGN KEY (`offid`) REFERENCES `officials` (`id`);

事务详细信息(从原始帖子编辑到显示外国密钥约束):

CREATE TABLE IF NOT EXISTS `transaction_details` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `xact_id` varchar(64) NOT NULL,
  `detail_amount` float(5,2) NOT NULL,
  `sport` varchar(10) NOT NULL,
  `regyr` varchar(250) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `xact_id` (`xact_id`)
) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8mb4;
ALTER TABLE `transaction_details`
  ADD CONSTRAINT `transaction_details_ibfk_1` FOREIGN KEY (`xact_id`) REFERENCES `transactions` (`txn_id`) ON DELETE CASCADE ON UPDATE CASCADE;

从信用卡公司接收数据后执行的代码,该行将行插入表中

// this creates the main transaction

    $sql = "INSERT INTO transactions (offid, txn_id, txn_time, approval_code, amount, result_message, ch_phone,
                          ch_card_type, ch_address, ch_state, ch_last_name, ch_email, ch_zip, ch_exp_date, ch_city, ch_first_name,
                          ch_transaction_type, ch_card_number) VALUES ('$offid', '$txn_id', '$txn_time', '$approval_code', '$amount', '$result_message',
                                                                       '$ch_phone', '$ch_card_type', '$ch_address', '$ch_state', '$ch_last_name', '$ch_email',
                                                                       '$ch_zip', '$ch_exp_date', '$ch_city', '$ch_first_name', '$ch_transaction_type', '$ch_card_number')";
    $result = mysqli_query($conn, $sql);

// this creates the detail transactions
if ($ssl_result == 0) {
    $detail_sports = array('fb', 'vb', 'sb', 'bb', 'wr', 'sw', 'so', 'ba', 'tr');
    foreach ($detail_sports as $sport) {
        $var = $sport . 'total';
        // cookie is set for fbtotal, vbtotal, etc. with an amount for that line item
        if (isset($_COOKIE[$var])) {
            $detail_amount = $_COOKIE[$var];
            $sql           = "INSERT INTO transaction_details (xact_id, detail_amount, sport, regyr) VALUES ('$txn_id', '$detail_amount', '$sport', '$regyear')";
            $result = mysql_query($sql);
        }
    }
}

:事务表的ID数字1、2、3、5、6、8、9、11、12、13、15、16、17等。这些都应连续编号,但不是。几乎好像它们被写入交易表(父)表,然后删除。但是该代码不会删除记录。

交易详细信息表与事务有多一对一的关系,其所有记录都包含连续的ID。

知道发生了什么事吗?

Here is the structure of the database tables in quesiton.

Officials:

CREATE TABLE IF NOT EXISTS `officials` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `last` varchar(250) NOT NULL DEFAULT '',
  `first` varchar(250) NOT NULL DEFAULT '',
  `middle` varchar(250) NOT NULL DEFAULT '',
  `address` varchar(250) NOT NULL DEFAULT '',
  `city` varchar(250) NOT NULL DEFAULT '',
  `state` varchar(250) NOT NULL DEFAULT '',
  `zip` varchar(250) NOT NULL DEFAULT '',
  `homeph` varchar(250) NOT NULL DEFAULT '',
  `workph` varchar(250) NOT NULL DEFAULT '',
  `cellph` varchar(250) NOT NULL DEFAULT '',
  `main_phone` varchar(10) DEFAULT NULL,
  `email` varchar(250) NOT NULL DEFAULT '',
  `notes` text NOT NULL,
  `blockreg` varchar(10) NOT NULL,
  `inactive` varchar(10) NOT NULL,
  `gender` varchar(100) NOT NULL,
  `minority` varchar(100) NOT NULL,
  `affiliate` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Is affiliate official? 0 = no. 1 = yes.',
  PRIMARY KEY (`id`),
  UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=14506 DEFAULT CHARSET=latin1;

Transactions (edited from original post to show foreign key constraints):

CREATE TABLE IF NOT EXISTS `transactions` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `offid` int(11) NOT NULL,
  `txn_id` varchar(64) NOT NULL,
  `txn_time` varchar(24) NOT NULL,
  `approval_code` varchar(24) DEFAULT NULL,
  `amount` varchar(8) NOT NULL,
  `result_message` varchar(100) NOT NULL,
  `ch_phone` varchar(10) NOT NULL COMMENT,
  `ch_card_type` varchar(4) NOT NULL,
  `ch_address` varchar(50) NOT NULL,
  `ch_state` varchar(15) NOT NULL,
  `ch_last_name` varchar(50) NOT NULL,
  `ch_email` varchar(100) NOT NULL,
  `ch_zip` varchar(10) NOT NULL,
  `ch_exp_date` varchar(4) NOT NULL,
  `ch_city` varchar(50) NOT NULL,
  `ch_first_name` varchar(30) NOT NULL,
  `ch_transaction_type` varchar(15) NOT NULL,
  `ch_card_number` varchar(18) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `txn_id` (`txn_id`) USING BTREE,
  KEY `offid` (`offid`)
) ENGINE=InnoDB AUTO_INCREMENT=72 DEFAULT CHARSET=utf8mb4;

ALTER TABLE `transactions`
  ADD CONSTRAINT `transactions_ibfk_1` FOREIGN KEY (`offid`) REFERENCES `officials` (`id`);

Transaction details (edited from original post to show foreign key constraints):

CREATE TABLE IF NOT EXISTS `transaction_details` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `xact_id` varchar(64) NOT NULL,
  `detail_amount` float(5,2) NOT NULL,
  `sport` varchar(10) NOT NULL,
  `regyr` varchar(250) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `xact_id` (`xact_id`)
) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8mb4;
ALTER TABLE `transaction_details`
  ADD CONSTRAINT `transaction_details_ibfk_1` FOREIGN KEY (`xact_id`) REFERENCES `transactions` (`txn_id`) ON DELETE CASCADE ON UPDATE CASCADE;

Code that executes upon receiving the data from the credit card company where rows are inserted into the table:

// this creates the main transaction

    $sql = "INSERT INTO transactions (offid, txn_id, txn_time, approval_code, amount, result_message, ch_phone,
                          ch_card_type, ch_address, ch_state, ch_last_name, ch_email, ch_zip, ch_exp_date, ch_city, ch_first_name,
                          ch_transaction_type, ch_card_number) VALUES ('$offid', '$txn_id', '$txn_time', '$approval_code', '$amount', '$result_message',
                                                                       '$ch_phone', '$ch_card_type', '$ch_address', '$ch_state', '$ch_last_name', '$ch_email',
                                                                       '$ch_zip', '$ch_exp_date', '$ch_city', '$ch_first_name', '$ch_transaction_type', '$ch_card_number')";
    $result = mysqli_query($conn, $sql);

// this creates the detail transactions
if ($ssl_result == 0) {
    $detail_sports = array('fb', 'vb', 'sb', 'bb', 'wr', 'sw', 'so', 'ba', 'tr');
    foreach ($detail_sports as $sport) {
        $var = $sport . 'total';
        // cookie is set for fbtotal, vbtotal, etc. with an amount for that line item
        if (isset($_COOKIE[$var])) {
            $detail_amount = $_COOKIE[$var];
            $sql           = "INSERT INTO transaction_details (xact_id, detail_amount, sport, regyr) VALUES ('$txn_id', '$detail_amount', '$sport', '$regyear')";
            $result = mysql_query($sql);
        }
    }
}

The transaction table has id numbers 1, 2, 3, 5, 6, 8, 9, 11, 12, 13, 15, 16, 17, etc. These should be consecutively numbered, but they aren't. It's almost as if they were written to the transaction (parent) table and then deleted. But the code doesn't delete a record.

The transaction detail table has a many-to-one relationship with transaction and all of its records contain consecutive ids.

Any idea what's going on?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文