Solved

Is there a way to automatically copy table data into a different table when it is submitted?

Posted on 2010-09-03
7
375 Views
Last Modified: 2012-05-10
I'd like to have a table automatically update another table when new data is entered . The tables will have 2 different names but similar fields if not all the same.

Is this possible?
Is there a snippet of  code, module, or plugin that can do this?

Thanks in advance.
0
Comment
Question by:colonelblue
7 Comments
 
LVL 11

Accepted Solution

by:
lenordiste earned 125 total points
ID: 33601314
you could use a trigger to update the second table.

here is a starting point:
http://dev.mysql.com/doc/refman/5.0/en/triggers.html
0
 
LVL 12

Assisted Solution

by:Rok-Kralj
Rok-Kralj earned 125 total points
ID: 33602013
I would personally solve this problem on php's level. If you have mysql_query() wrapped any way, you could just search for "INTO yourtable" to detect insertion and then perform necessary actions.

Apart from that, I suspect there is something wrong with the database/table design.
0
 
LVL 24

Expert Comment

by:lenamtl
ID: 33602801
Could you explain a little bit more what you try to achieve, are you looking for a specific bridge?
In the past I used Fabrick component http://fabrikar.com to make some complexe things this can help you.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:colonelblue
ID: 33603982
Hello experts and thank you for your replies.


The very purpose of why I am trying to replicate data from one table to another is to take advantage of a plugin that uses a zipocde proximity finder.

So how did I get here?

I was required to have an events application working for a site. Everything the Eventlist module can do, including having a calendar module and front-end input/edit form and nice layout.
But what it lacked was a search function based on zip codes (postcodes) which is the top requirement. I found that Sobi2 has a search function based on zip codes AND an extra plugin for it to use as a proximity finder.

Having both installed, the problem now is that they write to two different tables.
I had found a "module" someone made last year apparently from here: http://www.sigsiu.net/forum/index.php/topic,17407.10.html and included the zip if anyone is interested. However it does not work. No events show up in the module and the tables do not seem to see each other.

Now I thought I should just keep Sobi2 and it's handy zip code functions and not use Eventlist but Eventlist has that nifty little calendar and modules that make it so easy for the user.
SO I thought what if a user entered their data into EventList and then have that data replicated into the Sobi2 table? Then I can use both functions.


Again thank you for your expert advice.

mod-sobi2-eventlist.zip
0
 
LVL 1

Assisted Solution

by:dhaval_neesa
dhaval_neesa earned 125 total points
ID: 33605567
you can use the trigger for your problem
mysql> use shamun
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;

+------------------+
| Tables_in_shamun |
+------------------+
| contacts         |
| forum            |
+------------------+

2 rows in set (0.00 sec)

mysql> delimiter ;;
mysql> create trigger foo
-> after insert on forum
-> for each row
-> begin
-> insert into contacts (email) values ('example@abc.com');
-> end
-> ;;
Query OK, 0 rows affected (0.31 sec)

mysql> delimiter ;


// daily query
mysql> insert into forum (status) values ('open');
Query OK, 1 row affected, 13 warnings (0.00 sec)

mysql> select *from forum;

+----+--------+---------+------+------+------+
| id | status | subject | date | time | user |
+----+--------+---------+------+------+------+
|  2 | open   | NULL    | NULL | NULL | NULL |
+----+--------+---------+------+------+------+

1 row in set (0.00 sec)

mysql> select email from contacts;

+-----------------+
| email           |
+-----------------+
| example@abc.com |
+-----------------+

1 row in set (0.00 sec)

mysql>

http://dev.mysql.com/doc/refman/5.0/en/triggers.html
0
 
LVL 7

Assisted Solution

by:Vimal DM
Vimal DM earned 125 total points
ID: 33674587
hai,

I suggest you to study about the 'Cursors -' and DB that you want.

Where we can easily make the automatic update and what ever the functionality that you need.


Thanks.
0
 

Author Closing Comment

by:colonelblue
ID: 33873019
I could not figure this out.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now