Posting data on form to database

Hi,

I’m really struggling to get the dhtmlxform to operate correctly. I keep getting Undefined index: ids at /homepages/1/d76997751/htdocs/dhtmlxForm/dhtmlxForm/codebase/connector/form_connector.php line 47

!!!Uncaught Exception
Code: 0
Message: ID parameter is missed- could you help?

Code:

var dhxList;
	function doOnLoad() {

		var formData = [
			{type: "label", label: "Your Song Choices"},
			{type: "input", name: "forename", value: "", label:"First Name", bind: "Forename"},
			{type: "input", name: "surname", value: "", label:"Last Name", bind: "Surname"},
			{type: "input", name: "iD", value: "", label:"Song", bind: "ID"},
			{type: "input", name: "artist", value: "", label:"Artist", bind: "Artist"},
			{type: "input", name: "comment", value: "", label:"Comment", bind: "Comment", rows:3},


			{type: "button", name: "btn2", value: "Submit", command: "customCommand"}


			];
		
			
			dhxList = new dhtmlXForm("listObj", formData);


		dhxList.attachEvent("onButtonClick", function(name){
			if(name=="btn2"){
      			//alert("hi");
			var dp = new dataProcessor("insert2.php");
			dp.init(dhxList);
			alert("hi");
		        dhxList.save();
			alert("hi2");
				}

				});
	}


</script>

insert2.php

<?php require("dhtmlxForm/dhtmlxForm/codebase/connector/grid_connector.php"); require("dhtmlxForm/dhtmlxForm/codebase/connector/db_mssql.php"); require_once("dhtmlxForm/dhtmlxForm/codebase/connector/form_connector.php"); $res=MYSQL_CONNECT("dburl", "", "password"); MYSQL_SELECT_DB("db77050011"); /* Entering the values */ $form = new FormConnector($conn); $form->enable_log("log.txt"); $form->render_table("Insert into Guest forename,surname","Id","'',Forename,Surname"); ?>

Why do you init dataprocessor only before data sending?

Changing code as next, may help

dhxList = new dhtmlXForm("listObj", formData); var dp = new dataProcessor("insert2.php"); dp.init(dhxList);

Also, are you using connector.js on the page?
If not ( which is not common use-case, but still not critical ) , change init code as

dhxList = new dhtmlXForm("listObj", formData); var dp = new dataProcessor("insert2.php"); dp.setTransactionMode("POST", true); dp.init(dhxList);

Brilliant - that worked a treat!! A bit of tinkering on the sql as well and everything is now being saved correctly.

i have found another odd problem when I try to redirect to the results page. I still the get the undefined XML error. I can work around it by putting in an alert before calling the results php. Do you know why this is - Database lock?

dhxList.attachEvent(“onButtonClick”, function(name)
{
if(name==“btn2”){
if (dhxList.validate())
{
dhxList.save();

		alert("Saved your Song...");
		
		window.location = "http://www.joandkevin.co.uk/myjqgridphp.php"
		
	}}

});

Saving is async. , so you need to wait saving end before redirecting

dp.attachEvent("onAfterUpdate",function(){ window.location = "http://www.joandkevin.co.uk/myjqgridphp.php" }); dhxList.save();

Excellent - all working now! Thank you for your swift responses.