0

I have a table in database which has only one column and it stores the name of al the projects. I have one registration page which displays all these projects where user can select any . Any changes done on table reflects on my registration page.

User when selects the project and registers then all the information of the user is stored in another table that Database. My problem is if I do any changes in the table with projects name(delete or insert a name), it reflects on the registration page but it does not reflect on the user's database.

For example suppose one user has selected p1,p2 and registered and later if I delete p2 from the database, it does gets deleted from user's database, only its deleted from registration page. I want this change to be reflected everywhere. How do I implement this?

    <?php
    include('connection2.php');
    if(isset($_POST['project'])) {
           $pro=implode(',', $_POST['project']);

    $fname=$_POST['fname'];
    $lname=$_POST['lname'];
    $age=$_POST['age'];
    $gender=$_POST['gender'];
    $username=$_POST['username'];
    $username=$_POST['username'];
    $password=$_POST['password'];

    mysql_query("INSERT INTO test(fname, lname, age, gender, username, password,projects)VALUES
    ('$fname', '$lname', '$age', '$gender', '$username', AES_ENCRYPT
    ('$password','.b.'), '$projects')");
    }
    header("location: registration2.php?remark=success");
    mysql_close($con);
?> 
Jenz
  • 8,280
  • 7
  • 44
  • 77
  • 1
    Use triggers like in [here](http://stackoverflow.com/questions/11818191/mysql-trigger-delete-from-table-after-delete) – AyB Apr 28 '14 at 05:43
  • so users database is not same as the database you are using to store the project names? – pratim_b Apr 28 '14 at 05:43
  • same database but two diff tables. one table to store user info and other just to update project names – user3437250 Apr 28 '14 at 05:48
  • so where are users projects stored .. in the users table ? – lagbox Apr 28 '14 at 05:50
  • [**mysql_query is history**](http://us3.php.net/mysqli_query) ...please update your code!! :) – NoobEditor Apr 28 '14 at 08:35
  • table 1 with name test which has 7 columns as (fname, lname, age, gender, usernane, password, projects) and table 2 with name projects_name with only 1 column as name – user3437250 Apr 28 '14 at 08:55

1 Answers1

0

If you are using the same database, you can use the id of your project as foreign key. It actually depends upon your database structure. If you are storing as something like

user_1, project_1
user_1, project_2

In place of project_1 , you can use the id of your project table, and use cascade delete while deleting from your project table

userId, userName, project_id

where project_id will be your foreign key.

(You can also use trigger as suggested in the comment section. Although for this operation i will suggest cascade delete. If your operations are more complex then this, you can go for triggers or even stored procedure)

This SO POST has more details on how cascade delete works

Community
  • 1
  • 1
pratim_b
  • 1,160
  • 10
  • 29