我有一个用户数据库。每个用户在注册时都必须输入街道地址、州、城市、邮政编码。
我的数据库表中还有州、市、县、邮政编码。这些表格中填满了所有可用的美国州、县、市和邮政编码。
-Zipcodes are linked to cities only.
-Cities are linked to counties and states. Each city has unique city_id
-Counties are linked to states only. Each county has unique county_id
-Each state has unique state_id
我专门针对地址的 PHP 页面包括:
-SELECT for States (state_name as text; state_id as value)
-TEXTBOX for City (with only city_name as value)
-TEXTBOX for Zipcode
我使用 PHP Session 来存储用户输入的值,以防表单验证失败。
当用户提交时,我希望能够将 city_id 放入数据库(因为该 id 还将包含 County_id 和 state_id)。但是用户提交的是city_name。我怎么能匹配呢?
我是否需要在数据库中搜索表单验证并查看是否可以根据用户输入的内容找到城市?我想我需要一个完美的匹配。
根据用户键入的内容使用自动完成和检索 jquery 和 ajax 城市(包括 city_id),然后将 city_id 值存储在某处?
我该怎么做?