0

I am working on a project and I am using the eel python library to create GUI. I am using sqlite to store the database. I want to retrieve information and show it in different <input = text> input boxes.

But my output is [![It means I am getting all the output in one box][1]][1]

It means I am getting all the output in one box

My JavaScript code

function set_retrieve_2(name)
{
    document.getElementById("Name").value = name;
    document.getElementById("DOB").value = dob;
    document.getElementById("Sex").value = sex;
    document.getElementById("Address").value = address;
    document.getElementById("phone").value = phone;
    document.getElementById("Of_name").value = of_name;
    document.getElementById("Mem_Number").value = mem_number;
    document.getElementById("Mem_Date").value = mem_date;
}

My python code is

@eel.expose
def retrieved_2(nic):
    conn = sqlite3.connect("information_database")
    c = conn.cursor()
    c.execute("SELECT * FROM info WHERE NIC= ?", [nic])
    found = c.fetchone()
    if found:
        c = conn.cursor()
        c.execute("SELECT NIC FROM info WHERE NIC= ?", [nic])
        nic_n = c.fetchone()
        print(nic_n)
        c = conn.cursor()
        c.execute("SELECT name FROM info WHERE NIC= ?", [nic])
        name = c.fetchone()
        c = conn.cursor()
        c.execute("SELECT DOB FROM info WHERE NIC= ?", [nic])
        dob = c.fetchone()
        c = conn.cursor()
        c.execute("SELECT sex FROM info WHERE NIC= ?", [nic])
        sex = c.fetchone()
        c = conn.cursor()
        c.execute("SELECT address FROM info WHERE NIC= ?", [nic])
        address = c.fetchone()
        c = conn.cursor()
        c.execute("SELECT phone FROM info WHERE NIC= ?", [nic])
        phone = c.fetchone()
        c = conn.cursor()
        c.execute("SELECT of_name FROM info WHERE NIC= ?", [nic])
        of_name = c.fetchone()
        c = conn.cursor()
        c.execute("SELECT mem_number FROM info WHERE NIC= ?", [nic])
        mem_number = c.fetchone()
        c = conn.cursor()
        c.execute("SELECT mem_date FROM info WHERE NIC= ?", [nic])
        mem_date = c.fetchone()
        conn.commit()
        conn.close()
        return name, dob, sex, address, phone, of_name, mem_number, mem_date

Please help me thank you [1]: https://i.sstatic.net/AcFwk.png

1 Answer 1

1

Make the python function returns a dictionary/JSON object, which carries the results you want, so change

return name, dob, sex, address, phone, of_name, mem_number, mem_date

to

return { 'name' : name, 'dob' : dob, 'sex' : sex, 'address' : address, 'phone' : phone, 'of_name' : of_name, 'mem_number' : mem_number, 'mem_date' : mem_date }

and change the javascript code to

async function set_retrieve_2(name)
{
    var data=await eel.retrieved_2(name)();

    document.getElementById("Name").value = data.name;
    document.getElementById("DOB").value = data.dob;
    document.getElementById("Sex").value = data.sex;
    document.getElementById("Address").value = data.address;
    document.getElementById("phone").value = data.phone;
    document.getElementById("Of_name").value = data.of_name;
    document.getElementById("Mem_Number").value = data.mem_number;
    document.getElementById("Mem_Date").value = data.mem_date;
}

more clarifications and discussions would be upon comments.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.