# Button wont write to database

**URL:** <https://forum.inductiveautomation.com/t/button-wont-write-to-database/40598>\
**Category:** Maker\
**Tags:** perspective\
**Created:** [November 12, 2020, 7:33pm UTC](https://forum.inductiveautomation.com/t/button-wont-write-to-database/40598 "2020-11-12T19:33:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanbuckley2698](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@seanbuckley2698](https://forum.inductiveautomation.com/u/seanbuckley2698)\
**Post date:** [November 12, 2020, 7:33pm UTC](https://forum.inductiveautomation.com/t/button-wont-write-to-database/40598/1 "2020-11-12T19:33:25Z")

</div>

Hi, I am trying to get my button to write up the username and password when clicked, I have this code in the onActionPerformed in script. It is not writing to the database and i checked the connection and thats fine so Ive narrowed it down to the code. I copied the exam given by ignition to a point and made a few of my own changes but does not work, does anyone have any suggestions?

```auto
areaNum = self.getChild("txtUserUsername").props.text
machineName = self.getChild("txtUserPassword").props.text
system.db.runNamedQuery("LoginInsert", {"machineName":machineName, "areaNumber":areaNum})

```

---

<div class="post-metadata">

**Author:** ![schenk](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@schenk](https://forum.inductiveautomation.com/u/schenk)\
**Post date:** [November 12, 2020, 7:59pm UTC](https://forum.inductiveautomation.com/t/button-wont-write-to-database/40598/2 "2020-11-12T19:59:49Z")

</div>

Welcome Sean,

Perspective doesn’t have a [Client scope](https://docs.inductiveautomation.com/display/DOC81/Scripting+in+Perspective), so all scripting runs on the gateway. The [runNamedQuery](https://docs.inductiveautomation.com/display/DOC81/system.db.runNamedQuery) function requires a project name as the first parameter when run in the Gateway scope.

---

<div class="post-metadata">

**Author:** ![seanbuckley2698](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@seanbuckley2698](https://forum.inductiveautomation.com/u/seanbuckley2698)\
**Post date:** [November 12, 2020, 11:49pm UTC](https://forum.inductiveautomation.com/t/button-wont-write-to-database/40598/3 "2020-11-12T23:49:20Z")

</div>

Hello, would you have an example of the syntax?

---

<div class="post-metadata">

**Author:** ![seanbuckley2698](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@seanbuckley2698](https://forum.inductiveautomation.com/u/seanbuckley2698)\
**Post date:** [November 13, 2020, 12:01pm UTC](https://forum.inductiveautomation.com/t/button-wont-write-to-database/40598/4 "2020-11-13T12:01:42Z")

</div>

Hi schenk, I have ran this code but it is still not writing to my database, the “LoginInsert” at the end is the name of my query and isnt in the file path but I added it because I think thats what it says in the example. Any help would be appreciated.

```auto
Username = self.getChild("txtUserUsername").props.text
	Password = self.getChild("txtUserPassword").props.text		 
	system.db.runNamedQuery("FYP", "C:/Program Files/Inductive Automation/Ignition/data/projects/FYP/ignition/named-query/LoginInsert", {"Username":Username, "Password":Password})

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 13, 2020, 1:10pm UTC](https://forum.inductiveautomation.com/t/button-wont-write-to-database/40598/5 "2020-11-13T13:10:43Z")

</div>

Is the named query set for _Update Query_?

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/b/dbbcf7b2d314eba7c739ee8ebc32ce8fc8895659.png)

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [November 13, 2020, 1:16pm UTC](https://forum.inductiveautomation.com/t/button-wont-write-to-database/40598/6 "2020-11-13T13:16:15Z")

</div>

So paths for the named query aren’t the physical named path on the physical disk but the path in the project.

Try this:

```auto
Username = self.getChild("txtUserUsername").props.text
Password = self.getChild("txtUserPassword").props.text		 
system.db.runNamedQuery("FYP", "LoginInsert", {"Username":Username, "Password":Password})

```

See also what @JordanCClark is saying about it being an update query.

And if you could post a snapshot of the authoring tab so we can all see how you have things setup that would be a big help.

---

<div class="post-metadata">

**Author:** ![seanbuckley2698](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@seanbuckley2698](https://forum.inductiveautomation.com/u/seanbuckley2698)\
**Post date:** [November 13, 2020, 1:37pm UTC](https://forum.inductiveautomation.com/t/button-wont-write-to-database/40598/7 "2020-11-13T13:37:40Z")

</div>

Thanks bschroeder,

I changed my path as shown below and it worked perfectly.  
I had my named query set to the “Update Query” also.

Thanks for your help guys.

```auto
			# Grab the area number and machine name from the components we added to the window.
	Username = self.getSibling("txtUserUsername").props.text
	Password = self.getSibling("txtUserPassword").props.text		 
	# A call to our Named Query, inserting the two paramters using dictionary syntax.
	#system.db.runNamedQuery("LoginInsert", {"Username":Username, "Password":Password})
	
	system.db.runNamedQuery("FYP", "LoginInsert", {"Username":Username, "Password":Password})
	#C:/Program Files/Inductive Automation/Ignition/data/projects/FYP/ignition/named-query

```
