Python - Multiple SQL queries within code
<p>I am creating a Python script that receives an input (13 digit number). Then takes that number and checks if it's in my database (to check whether the person has registered). After that, it needs to check whether that person is logged in or not (in my database, I have a column called 'status' that is either 0 or 1). I can't, for the life of me, figure out how I can do the second query within my code.</p>

<p>I am using Python 2.7 with the MySQLdb module.</p>

<p>See my code below:</p>

<p>import MySQLdb</p>

<pre><code># Create a database connection
db = MySQLdb.connect(host="******", user="******", passwd="*****", db="******")
cur = db.cursor()

# Create a query to select all IDs
cur.execute("SELECT id, FROM users")
clientArray = []

# Loop over all IDs returned from query,
# save all IDs in the clientArray
for row in cur.fetchall():
    clientID = str(row[0])
    clientArray.append(clientID)
print clientArray #Printing for troubleshooting, ignore this


# Loop infinitely until - when you receive an input (which will be the clientID)
# check if the clientID exists in the clientArray.

# If the clientID exists, check to see whether the client has already been checked in
# If the client checkin returns FALSE, check the client in - turn on a GREEN LED light
# If the client checkin returns TRUE, check the client out - turn on a RED light

# If the clientID does not exist in clientArray, turn on the RED and GREEN LED lights

clientIDInput = ""
while True:
    clientIDInput = raw_input("")
    if clientIDInput in clientArray:
        print "The ID has been found in the database"
        # Check to see whether the person has been logged in or not

        ### THIS CODE DOES NOT WORK, CAN'T FIGURE THIS PART OUT ###
        cur.execute("SELECT status FROM users WHERE id='clientIDInput'")
        clientStatus = cur.fetchall()
        if clientStatus == True:
            print "This person is already checked in. Checking out now." 
            # Update MySQL database and change status from 1 to 0
        if clientStatus == False:
            print "This person has not checked in yet. Checking in now."
            # Update MySQL database and change status from 0 to 1        
    else:
        print " The ID has not been found in the database"
</code></pre>