MySQL and PHP regarding how to store information properly -


i need direction please. reading on mysql learned config db , keep running optimally need make db follows. example have

db members: holds~ 1-primary_id, 2-email, 3-password, 4-address_id, , 5-phone_id.  

ok know need make new db named db: address , db: phone

db address: holds~ 1-address_id(unique), 2-street, 3-city, 4-state, 5-zip 

finally db: phone

db phone: holds~ 1-phone_id(unique), 2-area code, 3-phone 

question #1: efficient way setup database? && correct?

question #2: when using php insert record html form. how ensure address inputted in form assigned db address , correct address_id recorded in db members? && same phone_id in db phone , db members?

thanks help!

what should mysql_query statement like?

mysql_query("insert members (email, password, address, phone, timestamp)  values('$email', 'sha($pass)', '$address', '$phone', now())"); 

how assign address address db , phone phone db? need use separate insert statements? , if so- how proper id's db members?

do not use sha() hash passwords

from mysql reference manual:

exploits md5 , sha-1 algorithms have become known. may wish consider using 1 of other encryption functions described in section instead, such sha2().

the mysql_* suite of functions should not continue used

"this extension not recommended writing new code. instead, either mysqli or pdo_mysql extension should used." -php.net

now, regarding questions

is efficient way setup database? && correct?

it depends. intend have 1 phone number per user, , 1 address per user? specifying address_id field on members table, limit amount of addresses member can limited to one. alternatively, if want allow user have number of addresses or phone numbers, phone , address tables should have references member--not other way around.

if do want 1 address , phone number per member, should include of information on members table. prevent unnecessary joins, , can specify want select.

if want multiple addresses , phone numbers, still might want to denormalize , use single table of data. have limit user reasonable number of addresses or phone numbers.

how ensure address inputted in form assigned db address , correct address_id recorded in db members? && same phone_id in db phone , db members?

if use mysqli, use insert_id property. if use pdo, use lastinsertid() method.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -