Database search to url redirect on button click

New to the coding aspect of wix & I’m not quite sure where to go from here. I’m guessing I’ll need some sort of fetch? maybe. I may be totally off base and need to do something entirely different.

Background Info–
I currently have a database(schoolClients) of client schools with fields as such:
schoolCode(text), schoolName(text), schoolsubsiteUrl(url)

What I Would like to accomplish–
When the client enters in their unique/nonpublic school code and clicks submit, the page then redirects to the schools unique subsite URL.

What I’ve done–
I’ve used the code found here https://support.wix.com/en/article/corvid-tutorial-adding-collection-data-search-functionality and have adjusted it to fit my scenario, however, I don’t want a table to show search results, and want it to redirect to the correct URL. As such I have ended the code at the .then(res =>

import wixData from “wix-data”;
export function searchButton_click(event) {
//Runs a query on the “schoolClients” collection
wixData.query(“schoolClients”)
// Query the collection for any items whose “schoolCode” field contains
// the value the user entered in the input element
.contains(“schoolCode”, $w(“#searchBox”).value)
.find() // Run the query
.then(res =>

So at the top of the code add:

import wixLocation from 'wix-location';

and in the then() part add:

.then((res) => {
    let item = res.items;
    if (item.length > 0) {
        let schoolLink = item[0].link; //use your own field key instead of "link"
    wixLocation.to(schoolLink);
    }
})
//and don't forget to close the onClick() function with a }

Hey There JD I am trying to achieve a similar thing. However, when I click on the button nothing is running.

Context - when a personal inputs into a user input text and click login in the page navigates to the URL in the data collection. business name field key “businessName” URL field key “urlLink”

Any help would be amazing

import wixLocation from 'wix-location';
import wixData from "wix-data";

export function login_click(event) {
wixData.query("vendorAssociate")
// Query the collection for any items whose "businessName" field contains
// the value the user entered in the input element
.contains("businessName", $w("#businessName").value)
.find()  // Run the query
.then((res) => {
let item = res.items;
if (item.length > 0) {
let location = item[0].urlLink; //use your own field key instead of "link"
wixLocation.to(location);
}
})
}

@tobympersonal I’m not sure I got your full explnation.
Anyway, make sure that all the property names, field key and collection name are correct.
Add these lines to see what if it logs:

Try to add console.log() 's to locate the problem:

//code.......
.then((res) => {
    console.log(res);
    let item = res.items;
    console.log(item);
    if (item.length > 0) {
    let location = item[0].urlLink; //use your own field key instead of "link"
    console.log(location);
    wixLocation.to(location);
    }
})
.catch(err => console.log(err));
}

i need a wix code for search data from contact form if find then redirect to another page if not find then show error messgae