Skip to main content
Topic: Action afterd Add (Read 2340 times) previous topic - next topic

Action afterd Add

Hi there, i need your help , I'm very beginner .
In my little project i have  one table "works"  with following columns : id;name ;date  . but i try  to make  an action after add data to create another table  where table name  must be like  name of the work ,this is the code inserted :
$db ->rawQuery ("CREATE TABLE `$rec_name` (
    `uuid` INT(11) NULL DEFAULT NULL,
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `unit_number` VARCHAR(255) NULL DEFAULT NULL,
    `instrument_type` VARCHAR(255) NULL DEFAULT NULL,
    `instrument_info` VARCHAR(255) NULL DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE INDEX `unit_number` (`unit_number`),
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
ROW_FORMAT=DYNAMIC
AUTO_INCREMENT=1
;")

Anyone can help me . Thanks in advance

Re: Action afterd Add

Reply #1
The error code :  SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name ''
                          C:\laragon\www\testrad\app\models\PDODb.php On Line 1611

......


Re: Action afterd Add

Reply #3
Thanks willvin for your attention , look attached file , this an example file  .
Note : if i change inside raw query $rec_name with $rec_id it work , but i want to name the table as $rec_name .
If need sql database writeme.

Re: Action afterd Add

Reply #4
sql file

Re: Action afterd Add

Reply #5
@Slax Rooth
Thanks willvin for your attention , look attached file , this an example file  .
Note : if i change inside raw query $rec_name with $rec_id it work , but i want to name the table as $rec_name .
If need sql database writeme.

because $rec_name does not exist, what exists is $rec_id and $modeldata['fieldname'], which is modeldata['id'], $modeldata['name'] and $modeldata['date'] for your works database table.

The following should be the correct thing in your Action After Add👇

Code: [Select]
$rec_name = modeldata['name'];

$db ->rawQuery ("CREATE TABLE `$rec_name`(
    `id` INT(11) NOT NULL,
    `name` VARCHAR(50) NULL DEFAULT NULL,
    PRIMARY KEY (`id`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
;");


 

Re: Action afterd Add

Reply #6
I want to  give  u a big hug for your patience and good explanation. Thank you very much