【发布时间】:2013-07-19 22:49:35
【问题描述】:
我有一个用户数据库。每个用户在注册时都必须输入街道地址、州、城市、邮政编码。
我的数据库中还有州、城市、县、邮政编码的表格。这些表格中填满了美国所有可用的州、县、市和邮政编码。
-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 值存储在某处?
我该怎么做?
【问题讨论】:
标签: php mysql ajax validation