Trouble for saving data to mysql database

I’m trying to save the dats of a simple form to a mysql table.
Here is my piece of code :

  function showTest() 
  {
  	dhxWins = new dhtmlXWindows();
        testWin = dhxWins.createWindow("testWin", 0, 0, 600, 350);
        testWin.setText("Ecran de test");
        testWin.setModal(true);
        testWin.denyResize();
	testWin.button("close").hide();
	testWin.button("park").hide();
  	testWin.button("minmax").hide();
        testForm = testWin.attachForm();  
	testForm.loadStruct("json/formAddItemDevis.json");
		
  	testForm.attachEvent("onChange", function(name, value)
  	{
  		switch(name) {
  			case "type_texte":
  				if (value == 'B')
  				{
  					testForm.showItem('biblio');
  					testForm.showItem('quantite');
  					testForm.showItem('prix_unit');
  					testForm.showItem('prix_total');
  				};
  				break;
  			case "biblio":
  				alert (value);
  				break;
  			case "prix_unit":
  				var prix_tot = testForm.getItemValue("quantite") * testForm.getItemValue("prix_unit");	
  				testForm.setItemValue("prix_total", prix_tot);
  			default:
  				break;	
  		};				
  	});

  	testForm.attachEvent("onButtonClick", function(name) 
  	{
    		switch(name) {
        		case "pbCancel" :
        		    testWin.close();
        		    break;
        		case "pbOK" :
        		    testForm.save();
        		    testWin.close();
        		    break;
        		default :
  				break;
  		};
  	});
  	
  	devisDP = new dataProcessor("php/devisCorpsTmpPDO.php");
		devisDP.init(testForm);

  };

Here is the code of devisCorpsTmpPDO.php :

'<?php
require_once("…/connector/form_connector.php");
require_once( “…/connector/db_pdo.php”);
require_once(“configPDO.php”);

$res = new pdo($srv, $user, $pwd);
$sql = “SELECT type_texte,num_lg,texte,quantite,prix_unit,prix_total FROM devis_corps_tmp”;

$form = new FormConnector($res,“PDO”);
$form->set_encoding(“iso-8859-1”);
$form->enable_log(“devisCorpsTmpPDO.log”);
$form->render_sql($sql, “id”, “type_texte,num_lg,texte,quantite,prix_unit,prix_total”);
?>

Here is what I get in the log :

====================================
Log started, 27/08/2018 02:08:01

DataProcessor object initialized
1535380151945_type_texte => B
1535380151945_biblio => 2
1535380151945_texte => I’m trying to save the datas of this form in a mysql table
1535380151945_quantite => 3
1535380151945_prix_unit => 12.5
1535380151945_prix_total => 37.5
1535380151945_num_lg =>
1535380151945_!nativeeditor_status => inserted
ids => 1535380151945

Row data [1535380151945]
type_texte => B
biblio => 2
texte => I’m trying to save the datas of this form in a mysql table
quantite => 3
prix_unit => 12.5
prix_total => 37.5
num_lg =>
!nativeeditor_status => inserted

INSERT INTO devis_corps_tmp(type_texte,num_lg,texte,quantite,prix_unit,prix_total) VALUES (‘B’,’’,‘I’m trying to save the datas of this form in a mysql table’,‘3’,‘12.5’,‘37.5’)

Array to string conversion at C:\wamp64\www\gestion\connector\db_pdo.php line 17

Edit operation finished
0 => action:error; sid:1535380151945; tid:1535380151945;

Done in 0.017305135726929s

I have the same problem without PDO.

Here is devisCorpsTmp.php :

’ <?php
require("…/connector/form_connector.php");
require (“configDB.php”);

$res=mysql_connect($srv, $user, $pwd);
if (!$res) { die('Connexion impossible: ’ . mysql_error()); }
mysql_select_db($db);

$form = new FormConnector($res,“MySQL”);
$form->set_encoding(“iso-8859-1”);
$form->enable_log(“devisCorpsTmp.log”);
$form->render_table(“devis_corps_tmp”, “id_devis”, “type_texte,num_lg,texte,quantite,prix_unit,prix_total”);
?>

Here is the log :

====================================
Log started, 27/08/2018 02:08:36

DataProcessor object initialized
1535380511297_type_texte => B
1535380511297_biblio => 2
1535380511297_texte => Here is a second test without PDO
1535380511297_quantite => 5
1535380511297_prix_unit => 14
1535380511297_prix_total => 70
1535380511297_num_lg =>
1535380511297_!nativeeditor_status => inserted
ids => 1535380511297

Row data [1535380511297]
type_texte => B
biblio => 2
texte => Here is a second test without PDO
quantite => 5
prix_unit => 14
prix_total => 70
num_lg =>
!nativeeditor_status => inserted

INSERT INTO devis_corps_tmp(type_texte,num_lg,texte,quantite,prix_unit,prix_total) VALUES (‘B’,’’,‘Here is a second test without PDO’,‘5’,‘14’,‘70’)

Edit operation finished
0 => action:error; sid:1535380511297; tid:1535380511297;

Done in 0.016704082489014s

Please, I need your help.

Best regards

Hy,

I answer myself.
I’ve forced variable num_lg= 1 and the insertion works.
But I don’t understand, in my table, NULL is authorized to that field.

If somebody has an idea. Thanks.

Now I’ve resolved this first problem I got a new one :

Here is my form :
form2save
When I click on “Quitter”, I save the datas and close the form
When I click on “Ajouter”, I save the datas, clean the form to add a new record.

Here is the peice of code I changed.

  	testForm.attachEvent("onButtonClick", function(name) 
  	{
    		switch(name) {
        		case "pbCancel" :
        		    testWin.close();
        		    break;
        		case "pbOK" :
        		    testForm.save();
        		    testWin.close();
        		    break;
  			case "pbAdd" :
  				testForm.save();
  				cleanForm();
  				break;
        		default :
  				break;
  		};
  	});
  	
  	devisDP = new dataProcessor("php/devisCorpsTmpPDO.php");
	devisDP.init(testForm);

  	function cleanForm()
  	{
  		testForm.clear();	
  		testForm.hideItem('biblio');
  		testForm.hideItem('quantite');
  		testForm.hideItem('prix_unit');
  		testForm.hideItem('prix_total');
  		testForm.setItemValue("quantite", 0);
  		testForm.setItemValue("prix_unit", 0);
  		testForm.setItemValue("prix_total", 0);
  		testForm.setItemValue("num_lg", 2);	
  		testForm.setItemValue("texte", "");
  	};

  }; 

But, in fact of adding a new record dataprocessor try to update.
How can I force to insert ?

Thanks for your help.

Best regards

But I don’t understand, in my table, NULL is authorized to that field.

Latest mysql can be configured to work in strict mode, where it will not accept string parameters for numeric fields. It can be changed in the configuration of mysql server. Of course, reconfiguring the server may be impossible, so you can use server side or client side data saving event to validate input and provide necessary default values.

But, in fact of adding a new record dataprocessor try to update.

There are two ways to switch form to the insert mode

  • clean form
form.clear();
form.resetDataProcessor("inserted");