Using wix the code works well in preview mode but the code doesn’t work after publishing

Database not getting updated.

Please add you code otherwise no one can help.

When something works in preview but not on published it almost always means there is a permission problem.

You can start by checking your database permissions to see who can view, add, edit or delete the content in that database.

1 Like

Facing problem in updating the “Request” database,
Kindly provide solution:
Provided the code below,
import wixData from ‘wix-data’;

export function reservation_click(event) {
// Fetch data from CartForm database
//$w(“#reservation”).onClick(() => {
wixData.query(“CartForm”)
.find()
.then((results) => {
if (results.items.length > 0) {
// Get the first item (assuming there’s only one)
const cartItem = results.items[0];
// Extract order status and order number
const orderStatus = cartItem.orderStatus;
const orderNumber = cartItem.orderNumber;

            // Get values from form input fields
            let name = $w('#name').value;
let email = $w('#email').value;
let code = $w('#countryCode').value;
let phone = $w('#phone').value;
let address = $w('#address').value;
let comments = $w('#comments').value;
let startDate = $w('#datePicker1').value;
let startTime = $w('#timePicker1').value;
let endDate = $w('#datePicker2').value;
let endTime = $w('#timePicker2').value;

console.log("Name: ", name);
console.log("Email: ", email);
console.log("Country Code: ", code);
console.log("Phone: ", phone);
console.log("Address: ", address);
console.log("Comments: ", comments);
console.log("Start Date: ", startDate);
console.log("Start Time: ", startTime);
console.log("End Date: ", endDate);
console.log("End Time: ", endTime);
// Get other form input values similarly…

            // Update Request database with collected data
            wixData.insert("Request", {
                name: name,
                email: email,
                countryCode: code,
                phoneNumber: phone,
                address: address,
                comments: comments,
                startDate: startDate,
                startingTime: startTime,
                endDate: endDate,
                endTime: endTime,
                orderNumber: orderNumber,
                orderStatus: 'Completed'

            })
            .then((results) => {
                // Handle successful database update
                console.log("Request added: ", results);
                // Optionally, show a success message or redirect to a thank you page
            })
            .catch((err) => {
                // Handle error
                console.error("Error inserting into Request database: ", err);
                // Optionally, show an error message
            });
        } else {
            console.warn("No items found in CartForm database.");
            // Optionally, show a message to the user indicating no items were found
        }
    })
    .catch((err) => {
        // Handle error
        console.error("Error querying CartForm database: ", err);
        // Optionally, show an error message
    });

}