Sean McVeigh
Posts: 0
Joined: Mon Feb 24, 2014 6:12 am

Help I'm tearing my hair out - Updating database field

I have a database with a single column ‘item’
In the application I have a page which displays this one ‘item’
I would like to have a text field in which the user can type an updated ‘item’
I would then like a button, which when clicked, updates ‘item’ with the text entered.

I have no idea of how to do this and been playing around with it for hours! Do I need to use a push service, local storage variable? I have no idea how to complete this simple task. If someone could take me through it step-by-step I would be eternally grateful!

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Help I'm tearing my hair out - Updating database field

Hi Sean,

No worries&desperation :)
This doc shows how to update Database http://docs.appery.io/documentation/b...
You will need to use Database Service http://docs.appery.io/documentation/b... with settings as at the link above.

You can try some tutorials as well http://docs.appery.io/tutorials/build...

Sean McVeigh
Posts: 0
Joined: Mon Feb 24, 2014 6:12 am

Help I'm tearing my hair out - Updating database field

I've had a look over these, but I'm still lost! Would anyone be willing to list the steps involved? I just want to be able to update the one thing being stored in my database.

Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

Help I'm tearing my hair out - Updating database field

You wanting to populate the text box with the existing item first ?

And then the user would remove that text and update it ?

Sean McVeigh
Posts: 0
Joined: Mon Feb 24, 2014 6:12 am

Help I'm tearing my hair out - Updating database field

I have successfully managed to populate the text box on the screen with the existing item from the database. I have placed an input box and update button on the screen. I just want the user to be able to enter new data and press update. Thank you so much for helping out!

Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

Help I'm tearing my hair out - Updating database field

Okay, so you need to use the update collection Service, and invoke it on the on the button clicked.

So create a new database service and pick update service on the collection name. When the item is returned, you need to capture the _id and put it in localStorage or a label thats not visible.

using the _id, you use the service and in the URL you need to add {id} at the end.

precode
https:&#47;&#47;api&#46;appery&#46;io/rest/1/db/collections/<collectionName>/{id}
/code/pre

In the request tab of the service, add 'id', and map the _id that you just stored to the value of id. Now it knows what object (row) it needs to update.

Then you need to add another request param 'item', and then map the populated edited text box to it.

Thats it! When the user visits that page, with the 'item' in the text box, it stores the _id. When the user changes the text and clicks the button, it invokes the service, uses the _id, and updates that col 'item' in the correct row.

Let me know if that helps and if you have success :)

Note: If you have more than one 'item' its best to use listview, and place a invisible label and populate the _id in that, so you know what each _id belongs too.

Sean McVeigh
Posts: 0
Joined: Mon Feb 24, 2014 6:12 am

Help I'm tearing my hair out - Updating database field

Thanks for your guidance. I'm getting there slowly - when I test the update service it is successful.

Sean McVeigh
Posts: 0
Joined: Mon Feb 24, 2014 6:12 am

Help I'm tearing my hair out - Updating database field

I'm getting there - I can update the database using the update service (test). Just can't get the text input to update my database when the button is pressed!

Sean McVeigh
Posts: 0
Joined: Mon Feb 24, 2014 6:12 am

Help I'm tearing my hair out - Updating database field

Fantastic! got it working - thank you so much (Bad Addy & Alena), you can't imagine how much I appreciate your help.

Cj Bernauer
Posts: 0
Joined: Wed Oct 22, 2014 5:47 pm

Help I'm tearing my hair out - Updating database field

Can you do this with multiple items in the data base?
Like changed all the stored values in a certain column in the database to something by clicking one button?

Like lets say I have columns identifying what data I'm collecting, and a column called "draft". Is there a way that you can update everything in the database in that column with one click?

Return to “Issues”