tags:

views:

43

answers:

2

Hello, I have one existing table for guests, with information such as name, passport number and such.

I want to make a new table for sales, and want to make it so that when a client is chosen from the existing table, certain fields are populated in the new table, such as passport number.

I am doing this with php and ajax.

Could someone point me in the general direction for where I should be looking to do this?

+1  A: 

You can do it from straight sql

$sql = "INSERT INTO sales (guest_id, passport_number) 
        VALUES ($guest_id, (SELECT passport_number FROM guests WHERE guest_id = $guest_id))";
Justin Giboney
How would I relate this query to the php code....for examle, if I choose a guest from a dropdown box, how would I have the passport field on the form immediately filled in?
Jacob
no need to fill in the passport field unless you want the user to see it. Just pass the guest_id to the code where your going to insert and then use that subquery (the second select statement) to grab your passport number.
Justin Giboney
A: 

Does the new sales table have to have it's own copy of the passport number, etc?
You can have a relation between the two tables, pointing to data in the original table from the sales table, for new customers that are already in the original table.

Check out:
http://php.about.com/od/learnmysql/ss/mysql_3.htm

http://en.wikipedia.org/wiki/Relational_database

Tommy