Validating new entries' zip codes in mysql table?

313
March 26, 2017, at 06:21 AM

I'm trying to validate new entries in a MySQL table by sending a GET request to the ZipCodeAPI (http://www.zipcodeapi.com/API). The API returns a json if the entry is valid. For new entries being inserted into the table, the API should verify that the entry in the postal_code column is valid. How would I allow the API to take in any possible zip code from the column postal_code in the table? Also, how would I test if the json is valid? Is there a function I could call that would determine if a json object is returned?

The code is in Python.

import requests
import mysql.connector
import json
dbconnect= mysql.connector.connect(user= 'root', database= 'contacts')
cursor = dbconnect.cursor()
url= "http://www.zipcodeapi.com/rest/QPIGMAfa0CmeyWWp0bum6rk3K6jdhK57zOOmo3xpFTDeQzERL8dRAyVlEeyWYE3x/info.json/06226/degrees"
response= requests.get(url)

data= jsonloads(response.content)
query= cursor.execute("INSERT INTO customer "
              "(id, ContactHash, NewContactHash, name, address1, address2, address3, city, country_code, country_code_iso2, state_province, postal_code, email_address, status, phone, CardCode, created_at, updated_at) 
              "VALUES (%d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)")

rows= cursor.fetchall()
for row in rows:
  json= response.json()
  if (json):
    print json
  else:
    print "Invalid zip code. Please try again."
Rent Charter Buses Company
READ ALSO
data not retrieving from online mysql server

data not retrieving from online mysql server

I am trying to get data from online database(MySql) through json and want to display it as a ListViewWhat I've done so far :

324
Importing mixed data from a file to a MySQL database

Importing mixed data from a file to a MySQL database

I have a file which is part of an export out of an ERP System,The content of the file is a mixture of csv and fixed text

286
upload multiple image into database using foreign key in laravel

upload multiple image into database using foreign key in laravel

this is POST table ,if i enter the record in POST table simultaneously the multiple image have to upload into the POST_Gallery tableplease help me this

322
Php MySQL Database error - undefined index [duplicate]

Php MySQL Database error - undefined index [duplicate]

This question already has an answer here:

452