PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 24, 2022

[FIXED] database phpmyadmin on insert trigger

 January 24, 2022     mysql, php, phpmyadmin     No comments   

Issue

Have this SQL.

CREATE TABLE `accounts` (
  `account_id` int(3) NOT NULL,
  `username` varchar(36) NOT NULL,
  `password` varchar(36) NOT NULL,
  `email` varchar(60) NOT NULL,
  `access_level` int(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `normal_profile` (
  `normal_profileid` int(11) NOT NULL,
  `first_name` varchar(64) NOT NULL,
  `middle_name` varchar(64) NOT NULL,
  `last_name` varchar(64) NOT NULL,
  `age` int(2) NOT NULL,
  `gender` varchar(6) NOT NULL,
  `account_id` int(3) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

ALTER TABLE `normal_profile`
  ADD CONSTRAINT `normal_profile_ibfk_1` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`account_id`);

phpmyadmin ui

The above is how i set constraints.

Whenever i insert something on to my accounts table, do i also have to query an insert into the normal_profile table? or can i automatically make it so that the DB itself will just add a row into normal_profile where account_id = accounts.account_id?

I have a vague memory of an on insert constraint or maybe im mistaken?

Adding Trigger UI phpmyadmin


Solution

try this syntax

delimiter #
     CREATE TRIGGER after_accounts
        AFTER insert ON accounts
         FOR EACH ROW
             BEGIN
          --  your insert query 
           end#

delimiter ;

enter image description here



Answered By - Ehsan Ilahi
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing