Inserting data from a dhtmlxForm into MySQL database

Hi,
I have a dhtmlxForm on a page. Following the samples, I am able to read data into the form from the database and update existing data to the database. I need help with coding the “Insert” and “Delete” commands. Is this a function of the DataProcessor and/or the Connector, if so where would I put the necessary code? For now this will be performed on a single table, but in the future it will be a multi-table “Insert” and “Delete”. I can write the SQL script for this, I just need to know where to put it.

Thanks in advance,
Joe

Hi,

you may find the information in the connector documentation.

docs.dhtmlx.com/doku.php?id=dhtm … xconnector

Here is the documentation for data updating, the same approach can be used for insert and delete operations:

docs.dhtmlx.com/doku.php?id=dhtm … ex_updates

Hi Alexandra,

First thank you for your reply. It was very helpful but I still have a question. I would like to use either of the following code snippet examples from the documentation:

   $id = $connector->insert(array(
      "type" => "simple",
   ));

This appears to be PHP code and I put it in a PHP file as follows:

<?php
   require_once('config.php');

   $id = $connector->insert(array(
      "Company_Name,Address1,Address2,Phone,Fax,
                        Email,Website,Promo,About_Us,Directions,Show_Visible,Featured,Tier2,Tier3" => "Company_Name,Address1,Address2,Phone,Fax,
                        Email,Website,Promo,About_Us,Directions,Show_Visible,Featured,Tier2,Tier3",
   ));
?>

Or

   $connector->sql->query("INSERT INTO some_table(type) VALUES('simple')");
   $id = $connector->sql->get_new_id();

I also put this into a PHP file named data_insert.php:

<?php
   require_once('config.php');


   $connector->sql->query("INSERT INTO Company(Company_Name,Address1,Address2,Phone,Fax,
                        Email,Website,Promo,About_Us,Directions,Show_Visible,Featured,Tier2,Tier3)
                        VALUES('Company_Name,Address1,Address2,Phone,Fax,
                        Email,Website,Promo,About_Us,Directions,Show_Visible,Featured,Tier2,Tier3')");
   $id = $connector->sql->get_new_id();
?>

My first question, is my code correct?
Second question, how would I call this function on the client side?
I have on the client side the following code connected to a “Add”,“Update” and “Delete” buttons:

        <script type="text/javascript">
            function DataInsert()

            function DataUpdate() {
                dp.sendData();
                
            }

            function DataDelete() 

</script>

As you can see only the update function works. If you could give me an example of how I would call the “Insert” and “Delete” functions that would be great. Thank you, your assistance is greatly appreciated!

Best Regards,
Joe

DataProcessor sends insert/update commands automatically. To define custom Insert handler you may use the same approach as for update here:

docs.dhtmlx.com/doku.php?id=dhtm … ide_events

but you need to use beforeInsert instead.

The last command of connector usage should be render_table or render_sql. One of this commands is necessary. Event handlers (beforeInsert/beforeUpdate) should be set before render method.

Form doesn’t provide remove operation. Therefore, this request is not sent.

Hi Alexandra,

That will work for me. Thank you again for your help!

Joe

I’m also trying to make an insert and delete button to a form. Your documentation is so confusing.

For a save/update event I can use the dataprocessor and add command=“save” to the save button. But when I delete or insert a record, I’ve got to use the connector instead and code the MySQL statement (INSERT/DELETE) by myself?

Why can’t I simply add command=“insert” or command=“delete” to the corresponding buttons of the form? Why are there no clear samples doing these basic working steps?

I want to insert also data from a dhtmlxForm to a MySQL database, but the link to the documentation is no longer available, anyone have the new links to the same resources in the actual documentation.

You can try to use our server-side Connector that is used in the following demo:

dhtmlxSuite/dhtmlxForm/samples/06_data/03_save.html