Create a textfield from database

[https://lemp06.wixsite.com/meinewebsite](https://lemp06.wixsite.com/meinewebsite

hello)

[hello](https://lemp06.wixsite.com/meinewebsite

hello) - this is my page - not finished at all yet -

What i try is that the field: “Großer Titel” next to the picture of Piko gets filled by a database.

The database i created with title and time shows the right time corresponding to the title Piko when i try the webpage in the preview, but when i publish the page it doesnt make the connection between database and website.

Also i made the code to update the time for Piko with the button “pikoDead” but it doesnt seem to work (my database is called Bosstimer):
export function Piko_Dead(event) {
var options = { timeZone: ‘Europe/London’ , timeZoneName: ‘short’ };
let optionsUpdate = {
“suppressAuth” : true ,
“suppressHooks” : true
};
const today = new Date();
let toUpdate = {
“title” : “Piko” ,
“time” : today.toLocaleTimeString( “en-GB” , options)
};
wixData.update( ‘Bosstimer’ , toUpdate, optionsUpdate)
}

So nun zu dir mein Freund :laughing: (sieht etwas durcheinander aus dein online-game).

  1. First at all, please use CODE-TAGS …like…
here my code in CODE-TAGS ! (grey-field = CODE-TAG)
  1. You are using hooks, i do not work with hooks (alles nur hokus-pokus diese hooks).

  2. You should perhaps also show your Database (structure), to understand better what you are trying to do.

  3. Do you use a REPEATER?

Mehr INPUT wäre nicht schlecht :wink: und beschreibe mal den genauen Ablauf den du generieren möchtest.

  1. Describe a little bit more what is the flow of your project?

  2. You have a Database (Data-Collection) —> “Bosstimer”

  3. There you store your some “title” with it’s related reference —> “time”

  4. When you click on a button, is this button located in a repeater?

  5. You want the “date” and the “title” to be updated in your database, right?

  6. Or do you wanna also chnge the title next to the butto ?

You should work with …(DATA-query if you want to get something out of DB…

import wixData from 'wix-data';

wixData.query('Bosstimer')
 .find()
 .then( (results) => {
     if(results.items.length > 0) {
       let firstItem = results.items[0]; 
       console.log(results)
      
      
    } else {
      // handle case where no matching items found
    }
  } )
  .catch( (err) => {
    let errorMsg = err;
  } );

And here you have a code-snipet which will update DATA in DB…

import wixData from 'wix-data';

let toUpdate = {"title":        "Piko","time":   today.toLocaleTimeString("en-GB", options)    };

wixData.update('Bosstimer', toUpdate)
	.then( (results) => {
		let item = results; 
		console.log(results)
	} )
	.catch( (err) => {
		let errorMsg = err;
	} );

Put it into a function… something like that…

import wixData from 'wix-data';
  
function meineFunktion(){ 
	let toUpdate = {"title":        "Piko","time":   
	today.toLocaleTimeString("en-GB", options)    };

	 wixData.update('Bosstimer', toUpdate)
	.then( (results) => {
		let item = results; 
		console.log(results)
	} )
	.catch( (err) => {
		let errorMsg = err;
	} );
}

Naja und den REST machst du dann auf eigene Faust :wink: