This should help you, try it, as I've just tried it and it works properly without having to insert a new record manually typing via Add on-the-fly.
Generate this following sql script to generate the required tables and some data sample inside each table:
/*
Navicat Premium Data Transfer
Source Server : MySQL localhost
Source Server Type : MySQL
Source Server Version : 50617
Source Host : 127.0.0.1:3306
Source Schema : lookuptable
Target Server Type : MySQL
Target Server Version : 50617
File Encoding : 65001
Date: 19/02/2018 14:55:05
*/
-- Begin of tables schema
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- Table structure for fach2018
DROP TABLE IF EXISTS fach2018
;
CREATE TABLE fach2018
(
ID
int(11) NOT NULL AUTO_INCREMENT,
Event_Name
varchar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
Start
datetime(0) NULL DEFAULT NULL,
End
datetime(0) NULL DEFAULT NULL,
Project_ID
int(11) NULL DEFAULT NULL,
PRIMARY KEY (ID
) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Compact;
-- Records of fach2018
INSERT INTO fach2018
VALUES (1, 'First Event', '2018-02-01 14:53:28', '2018-02-02 14:53:28', 1);
INSERT INTO fach2018
VALUES (2, 'Second Event', '2018-02-02 14:53:51', '2018-02-03 14:53:51', 2);
-- Table structure for projects
DROP TABLE IF EXISTS projects
;
CREATE TABLE projects
(
ID_Project
int(11) NOT NULL AUTO_INCREMENT,
Project_Name
varchar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
Start
datetime(0) NULL DEFAULT NULL,
End
datetime(0) NULL DEFAULT NULL,
PRIMARY KEY (ID_Project
) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Compact;
-- Records of projects
INSERT INTO projects
VALUES (1, 'First Event', '2018-02-01 14:53:28', '2018-02-02 14:53:28');
INSERT INTO projects
VALUES (2, 'Second Event', '2018-02-02 14:53:51', '2018-02-03 14:53:51');
SET FOREIGN_KEY_CHECKS = 1;
-- End of tables schema
Put the following code in "Row_Inserted" server event that belongs to "fach2018" table:
ew_Execute("INSERT INTO projects
(Project_Name, Start, End) VALUES ('" . $rsnew["Event_Name"] . "', '" . $rsnew["Start"] . "', '" . $rsnew["End"] . "')");
$Last_ID = ew_ExecuteScalar("SELECT ID_Project
FROM projects
WHERE Project_Name
= '" . $rsnew["Event_Name"] . "'");
ew_Execute("UPDATE fach2018
SET Project_ID
= " . $Last_ID . " WHERE Event_Name
= '" . $rsnew["Event_Name"] . "'");
And put the following code in "Row_Rendered" server event that belongs to the "fach2018" table:
if (CurrentPageID() == "add" || CurrentPageID() == "edit") {
$this->Project_ID->Visible = FALSE;
}