Hi all,
I have two tables in a mysql db:
TABLE A (classroom)
id_cla [int(3)]
name_cla [varchar(255)]
seats_cla [int(3)]
max_seats_cla [int(3)]
TABLE B (students)
id_stu [int(3)]
name_stu [varchar(255)]
classroomid_stu [int(3)]
I have a form where the student will be able to subscribe to a classroom.
When the student will subscribe he will select the classroom from a dropdown menu.
Once he submits the form a record will be inserted in Table B, containing student name and the choosen classroom; at the same time the seats_cla in Table A should be updated/incremented (adding 1 to the actual field content).
Is there a way to do this with ADDT?
TIA for any help.
tony
update a field in another table when inserting record
-
- Posts: 37
- Joined: 2010-04-28 08:34
Re: update a field in another table when inserting record
A custom trigger of type AFTER should do.
Code: Select all
function Trigger_Custom(&$tNG) {
$id_cla = $_POST['whatever class he selected'];
mysql_query("UPDATE classroom SET seats_cla = seats_cla+1 WHERE id_cla = '$id_cla'");
}