Form data to database

#1

I am trying to insert the form values in mysql using xampp server, but it is showing this error.
please help.

#2

The SQL you are executing is No Good. As the debug says, you are not providing a value for something that requires a value.

You should attach a debug to each node on your flow and inspect the output. That will help you narrow down the issue.

#3

I am getting null value when my query is executing but form has data .please guide me where i am wrong

#4

As you can see you are trying ti insert Emp_Id with a value of null (first element of the array) and your database is set to not allow that.

#5

sir , i am providing the value but i don't know y it's taking null . please see the second output which is of form output.

#6

The form is sending an object and the sql wants an array - so your function is not providing that.

#7

so, how can we do that . how can we provide array instead of object.

#8
  1. What does the query look like that you are building in the function node?

  2. Where do you put this query? (see the info box for the mysql node)

  3. change your debug nodes to display the complete msg object

#9

[{"id":"e8e5e50e.b83968","type":"mysql","z":"166ff6a7.0b0779","mydb":"6474c2f6.29a27c","name":"","x":570,"y":60,"wires":[["2b34346d.15f73c"]]},{"id":"6474c2f6.29a27c","type":"MySQLdatabase","z":"","host":"127.0.0.1","port":"3306","db":"silvan","tz":""}]
here i attached my flow.

#10

What I see is the form is passing your input as an object

{
id: "", name:"",Father_name:"",DOJ:""
}

From looking at your SQL INSERT statement you should be sending an array.

You need to convert the properties of the form input into an array.

off the opt of my head ...

var formData = msg.payload;
var dataForInsertQuery = [];
dataForInsertQuery.push(formData.id);
dataForInsertQuery.push(formData.name);
dataForInsertQuery.push(formData.Father_name);
dataForInsertQuery.push(formData.DOJ);

...should put you closer to a solution

#11

no, its not working

#12

Please show the debug output when something doesn’t work and a copy of the code you used. You could have made a typo....

Also you only provided the MySQL node not your complete flow.

#13

[{"id":"166ff6a7.0b0779","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"f105783c.907508","type":"ui_form","z":"166ff6a7.0b0779","name":"","label":"","group":"1693ba1c.3fe0f6","order":4,"width":0,"height":0,"options":[{"label":"Emp_id","value":"id","type":"text","required":true},{"label":"name","value":"name","type":"text","required":false}],"formValue":{"id":"","name":""},"payload":"","submit":"submit","cancel":"cancel","topic":"","x":110,"y":180,"wires":[["6ffadafe.da5624","f542a33.433356"]]},{"id":"6ffadafe.da5624","type":"function","z":"166ff6a7.0b0779","name":"insert Query","func":"msg.topic="INSERT INTO test(Emp_Id,name) VALUES (?,?)";\nmsg.payload=[msg.payload.Emp_Id,msg.payload.name];\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":80,"wires":[["e8e5e50e.b83968","c21b9501.cc5fd8"]]},{"id":"e8e5e50e.b83968","type":"mysql","z":"166ff6a7.0b0779","mydb":"6474c2f6.29a27c","name":"","x":550,"y":60,"wires":[["2b34346d.15f73c"]]},{"id":"2b34346d.15f73c","type":"debug","z":"166ff6a7.0b0779","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":670,"y":260,"wires":},{"id":"f542a33.433356","type":"debug","z":"166ff6a7.0b0779","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":230,"y":340,"wires":},{"id":"c21b9501.cc5fd8","type":"debug","z":"166ff6a7.0b0779","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":420,"y":240,"wires":},{"id":"1693ba1c.3fe0f6","type":"ui_group","z":"","name":"test","tab":"478ee339.c9145c","order":1,"disp":true,"width":"6","collapse":false},{"id":"6474c2f6.29a27c","type":"MySQLdatabase","z":"","host":"127.0.0.1","port":"3306","db":"silvan","tz":""},{"id":"478ee339.c9145c","type":"ui_tab","z":"","name":"puri","icon":"dashboard","disabled":false,"hidden":false}]
this is the flow.

#14

Where did you come up with msg.payload.Emp_id in your function?

#15

i am trying to send those value to my table . i used msg.payload because it used to send the output in array.

#16

@zenofmud sir now i am getting this error

#17

Look at your debug output that is going into the function node. What are the names of the elements in msg.payload?

#18

okay. can you tell me how i can send form data as in array .

#19

What are the names of the items in msg.payload?
What names are you using in the function node?
Are they the same?

P.s. yes I could tell you the answer, but it’s better for you to figure it out yourself and learn something

#20

yes , they are same . the names are Emp_Id and name.