1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Need help updating another table with php plugin on form submission

Discussion in 'Community' started by AlexTCGPro, Oct 7, 2019.

  1. AlexTCGPro

    AlexTCGPro Member

    Level: Community
    Hello, I'm new to using fabrik and I'm trying to use it as a way to make my job easier at a college.

    I have two tables, one called 'students' and the other 'inscriptions'.
    I want that when someone adds an entry in 'students' that another one gets added to 'inscriptions' as well but just with some of the values. Like this:

    When you submit a new student you need to put ID, full name, birthday, grade, year, generation, hours and more personal data.
    I want that a new row gets created to 'inscriptions' containing only ID, grade and year, the same data that was in the other form.

    The idea is that the first list 'students' will only have data from current year, and the list 'inscriptions' will have the story of the students with a list of all the years and hours they had over the years.

    I'm working with this code but it's clearly incomplete, I have no experience with mysql and I get lost reading all the documentations
    Code (Text):
    $db = JFactory::getDBO();
    $id= JRequest::getVar('students___student_id');
    $grade= JRequest::getVar('students___grade');
    $year = JRequest::getVar('students___year');
    $db->setQuery("update inscriptions set grade = '$grade' where student_id = $id" and year = "$year");
    That should update the grade field according to year and id, correct? I haven't tested it yet but that should't work, right? Since no rows exist there's nothing to update, I will really appreciate if you could give me a hand
  2. troester

    troester Well-Known Member Staff Member

    Level: Community
    Last edited: Oct 8, 2019
  3. AlexTCGPro

    AlexTCGPro Member

    Level: Community
    Thank you for replying, I just found the upsert plugin, can't that do the thing I want but without that much coding?
  4. troester

    troester Well-Known Member Staff Member

    Level: Community
    That's what upsert is for.
    But it depends on what you want to do.

Share This Page