ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How can I allow members to add/edit/delete data from non EE database tables from within EE?

May 19, 2008 11:14am

Subscribe [3]
  • #1 / May 19, 2008 11:14am

    smalljohnson

    13 posts

    I have a site that includes both EE tables and non EE tables in the same EE database.  The non EE tables contains various data related to the members of the site (like addresses, contact information, payment transactions, etc).  These non EE tables are from another web application that can access and modify the non EE tables.

    I have created a custom field in the member profile that is an ID that links the member in EE to the non EE tables in the database.

    I need to create an interface that allows members to be able to create, modify, and delete their data from the non EE tables in the database.

    I am currently able to display that data for the current logged in member in EE by using the database class and the custom member field ID.

    How do I go about creating the forms (can I use SAEF or Freeform?) to allow members to add, update and delete their information (using the non EE tables)?  The documentation seems to indicate SAEF will only work with weblogs.  Not sure about Freeform but that looks like it might only work withs its own db tables.  Where do I put the code that processes the forms and updates the database?  What about validation and prepopulation?  If I use GET or POST, how do I stop other members from modifying other members information?  Anyone have any examples?

  • #2 / May 19, 2008 12:05pm

    To show members the data from the nonEE tables you can use the query module, but this is only for showing the data. I would use this with the

    {if logged_in}{/if}


    tags.

    In terms of editing these tables you would need to use PHP. I would personally do everything on the same page and use post so the variables can’t be seen.

    <form method='post' action='/thispage>'

    At the top of the page use the PHP isset() method to find out if the form has been submitted and deal with the update

    <?php
       
        if (isset($_REQUEST[form_field_name])) {
            
            //connect to database
            $username = "";
            $password = "";
            $hostname = "localhost";
    
    
            $dbhandle = mysql_connect($hostname, $username, $password)
     or die("Unable to connect to MySQL");
    
            //select a database to work with
            $selected = mysql_select_db("database_name",$dbhandle)
      or die("Could not select database");
    
            $result = mysql_query("UPDATE table_name…");
    
        }
    
    ?>

    Its not too complicated PHP but it does require a bit of programming knowledge. Try this link for your update query. Or if you just want to learn more able using PHP with MySQL try this

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases