# Using system.db.runPrepUpdate

**URL:** <https://forum.inductiveautomation.com/t/using-system-db-runprepupdate/10453>\
**Category:** Ignition\
**Created:** [September 11, 2015, 3:39pm UTC](https://forum.inductiveautomation.com/t/using-system-db-runprepupdate/10453 "2015-09-11T15:39:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alewayhar](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alewayhar](https://forum.inductiveautomation.com/u/alewayhar)\
**Post date:** [September 11, 2015, 3:39pm UTC](https://forum.inductiveautomation.com/t/using-system-db-runprepupdate/10453/1 "2015-09-11T15:39:01Z")

</div>

I am trying to add a row into a SQL DB table. I have successfully used the following code in mySQL so I know that my SQL code should not have any syntax errors.

`INSERT INTO sensor_notes (user, timestamp, sensor_number, notes)
VALUES ('name', 'currenttime', 'sensor_number', 'notes')`

When I place it into ignition I know I have to change the VALUES so that they reflect defined variables within my scripting, and the following is my scripting code:

[code]user = “[System]Client/User/Username”  
timestamp = “[System]Client/System/CurrentDateTime”  
sensor\_number = event.source.parent.sensorNumber  
notes = event.source.parent.getComponent(‘Text Area’).text

insertQuery = “”“INSERT INTO sensor\_notes (user, timestamp, sensor\_number, notes)  
VALUES (‘user’, ‘timestamp’, ‘sensor\_number’, ‘notes’)”""

system.db.runPrepUpdate(insertQuery, [user, timestamp, sensor\_number, notes], ‘db’)[/code]

I keep getting errors that this is not correct and I’m not sure what I am missing in my code. Any help would be appreciated so much! This is driving me crazy! 😮

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [September 11, 2015, 4:09pm UTC](https://forum.inductiveautomation.com/t/using-system-db-runprepupdate/10453/2 "2015-09-11T16:09:18Z")

</div>

This should get you going unless you have already figured it out

[code]insertQuery = “INSERT INTO sensor\_notes (user, timestamp, sensor\_number, notes)  
VALUES (?, ?, ?, ?)”

system.db.runPrepUpdate(insertQuery, [user, timestamp, sensor\_number, notes], ‘db’)[/code]

---

<div class="post-metadata">

**Author:** ![alewayhar](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alewayhar](https://forum.inductiveautomation.com/u/alewayhar)\
**Post date:** [September 11, 2015, 4:15pm UTC](https://forum.inductiveautomation.com/t/using-system-db-runprepupdate/10453/3 "2015-09-11T16:15:46Z")

</div>

😃😃😃 YOU ARE MY HERO!!! ![:prayer:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e5a7e3b63facc151ea73e3b45db7bdb3d4bdc316.gif ":prayer:")

That worked. That had been kicking my butt for weeks…
