title: Python MySQL plate number matching with two tables before inserting into another table
body: <p>I have 3 Tables. </p>
  
  <p>First is the <code>Registered Plate Table</code></p>
  
  <p>Second is the <code>Unregistered Plate Table</code></p>
  
  <p>Third is the <code>Vehicle_Login Table</code></p>
  
  <p>in Registered Table I have a plate number <code>AAA4890</code></p>
  
  <p>in Unregistered Table I have a plate number <code>AAA890</code></p>
  
  <p>then I have a function that will accept the <code>recognized plate</code>.The possible recognition of ocr was <code>AAA890</code> and <code>AAA4890</code> and etc(which I will dump). Before I insert the <code>recognized plate</code> in the <code>Vehicle_login</code> I want to compare the <code>recognized plate</code> into the plates of <code>Registered Table and Unregistered table</code>. If the recognized plate doesn't match the plates with my two tables. I will dump it, otherwise I will insert it into <code>Vehicle_Login</code> depending also on which table and it's plates is matched.</p>
  
  <p>Also if the <code>recognized plate</code> is already in the <code>Vehicle_Login</code> I will not insert it again with this I can prevent multiple values inserting it again. I am reading frames from an Ip cam and every frame my program recognize it.</p>
  
  <pre><code>    add_plate = "INSERT INTO vehicle2_login (plate,status,time_login) values (%s,%s,%s)" 
      ts = time.time()
      st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
  
      last_id = "SELECT * FROM vehicle2_login WHERE id=(SELECT MAX(id) FROM `vehicle2_login`)"
      cursor.execute(last_id)
      record = cursor.fetchall()
      last_plate = record[0][1]
  
      sql = "SELECT * FROM registered where plate = %s"
      cursor.execute(sql, (plate, ))
      result_set = cursor.fetchall()
      checker = ""
      for row in result_set:
          if plate == row[2]:
              checker = True
          elif plate != row[2]:
              checker = False
          else:
              checker = False
  
      sql2 = "SELECT * FROM unregistered where plate = %s"
      cursor.execute(sql2, (plate, ))
      result_set2 = cursor.fetchall()
      checker2 = ""
      for row2 in result_set2:
          if plate == row[1]:
              checker2 = True
          elif plate != row[1]:
              checker2 = False
          else:
              checker2 = False
      if checker or not checker2:
          status = "Registered"
          data_plate = (plate,status,st)
          print("This plate number", plate, "is Registered \n")
          if plate == last_plate:
              print("Cannot insert it's already logged in \n")    
          else:
              cursor.execute(add_plate, data_plate)
              mydb.commit()
      elif not checker or checker2:
          status = "Unregistered"
          data_plate = (plate,status,st)
          print("This plate number", plate, "is Unregistered \n")
          if plate == last_plate:
              print("Cannot insert it's already logged in \n")    
          else:
              cursor.execute(add_plate, data_plate)
              mydb.commit()
      elif not checker and not checker2:
          print(plate, "was Dumped!")
  </code></pre>