我通過添加反饋表來修改現有項目。我需要將反饋表單數據存儲到一個名為feedback_formtb的表中。我編寫了 sql 代碼來創建這個表。還有一個已經創建的表調用profile_request,我想從這個profile_request表中獲取一個外鍵。因此,我將 request_id 字段添加為外鍵。(我無權編輯 profile_request 表,因為該部分已經開發)我創建了一個名為feedback_test.php的文件。現在我想將反饋表單數據插入到 feedback_formtb 表中。我按照我的理解做了。但是由于外鍵,我不確定這個 sql 插入查詢是否正確,我是否正確地將數據插入到表中。(我沒有用戶界面,因為我要求將此反饋表單添加到現有項目中)。如果有人可以幫助我判斷這在哪里可以,真的很感謝您的幫助。提前致謝。===============feedback_formtb 表創建===================DROP TABLE IF EXISTS `feedback_formtb`; CREATE TABLE IF NOT EXISTS `feedback_formtb` ( `fid` int(10) NOT NULL, `job_complete` tinyint(2) NOT NULL, `satisfaction` double NOT NULL, `reason` int(20) NOT NULL, `comment` text NOT NULL, `request_id` int(10) NOT NULL, PRIMARY KEY (`fid`), FOREIGN KEY (`request_id`) REFERENCES profile_requests(`id`) )ENGINE=InnoDB DEFAULT CHARSET=latin1;=============profile_requests 表=================DROP TABLE IF EXISTS `profile_requests`;CREATE TABLE IF NOT EXISTS `profile_requests` ( `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), `created_at` timestamp NOT NULL DEFAULT current_timestamp(), `created_by` int(10) UNSIGNED NOT NULL, `updated_by` int(10) UNSIGNED NOT NULL, `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, `user_id` int(10) UNSIGNED NOT NULL, `profile_id` int(10) UNSIGNED NOT NULL, `expected_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `lat` float UNSIGNED NOT NULL, `lng` float UNSIGNED NOT NULL, `city_id` int(11) NOT NULL, `message` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `state` tinyint(3) UNSIGNED NOT NULL DEFAULT 1 COMMENT '1:new request, 2:accepted,3:rejected', `urgent` tinyint(3) UNSIGNED NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=69 DEFAULT CHARSET=latin1;
1 回答

米脂
TA貢獻1836條經驗 獲得超3個贊
您不需要子查詢。只需$request_id用作列的值。
$ips = $mysqli->prepare('
INSERT INTO feedback_formtb (job_complete, satisfaction, reason, comment, request_id)
VALUES (?, ?, ?, ?, ?)');
外鍵約束將確保它$request_id是有效的。如果您嘗試插入 中不存在的 ID,profile_requests則會出現錯誤。
- 1 回答
- 0 關注
- 119 瀏覽
添加回答
舉報
0/150
提交
取消