Hey, so I have a form and i want to break down the form into 2 sections when inserting into my database. I have made 2 tables to hold my values.
this is my SQL statements.
$sql_insert1 = "INSERT INTO `agent_users`
(`user_name`,
`password`,
`primary_email`,
`secondary_email`,
`join_date`,
`last_accessed`,
`activation_code`,
`first_name`,
`last_name`,
`license_num`,
`agent_dob`
)
VALUES
('$data[user_name]',
'$md5pass',
'$usr_email',
'$data[secondary_email]',
'now()',
'date()',
'$activ_code',
'$data[first_name]',
'$data[last_name]',
'$data[license_num]',
'$dob'
)";
$sql_insert2 = "INSERT INTO `agent_company`
(`exp_age_yr`,
`exp_age_mo`,
`exp_sales`,
`exp_sSales`,
`exp_reo`,
`exp_propmngt`,
`exp_foreclosures`,
`exp_lMods`,
`exp_bpo`,
`exp_commreal`,
`company_name`,
`company_address`,
`company_suite`,
`company_city`,
`company_state`,
`company_zip`,
`company_tel`,
`company_tel_ext`,
`company_fax`,
`company_web`
)
VALUES
('$data[exp_age_yr]',
'$data[exp_age_mo]',
'$chkbx_results[exp_sales]',
'$chkbx_results[exp_sSales]',
'$chkbx_results[exp_reo]',
'$chkbx_results[exp_propmngt]',
'$chkbx_results[exp_foreclosures]',
'$chkbx_results[exp_lMods]',
'$chkbx_results[exp_bpo]',
'$chkbx_results[exp_commreal]',
'$data[company_name]',
'$data[company_address]',
'$data[company_suite]',
'$data[company_city]',
'$data[ompany_state]',
'$data[company_zip]',
'$data[company_tel]',
'$data[company_tel_ext]',
'$data[company_fax]',
'$data[company_web]'
)";
mysql_query($sql_insert1,$link) or die("Insertion Failed:" . mysql_error());
$user_id = mysql_insert_id($link);
$md5_id = md5($user_id);
mysql_query("UPDATE `agent_users` SET md5_id='$md5_id' WHERE id='$user_id'");
mysql_query($sql_insert2,$link2) or die("Insertion Failed:" . mysql_error());
$user_id2 = mysql_insert_id($link);
//$new_id = mysql_query("SELECT `id` FROM `agent_users` WHERE id='$user_id'");
mysql_query("UPDATE `agent_company` SET company_id='$user_id'");
I was trying to insert my values into my agent_users table and then also insert their company information into my agent_company table.
My logic was in order for me to connect these tables to one member or user what ever you want to call it. to be connected by the agent_user `id` field, which is set to auto_increment.
What would I need to do get the `id` number to match up with the agent_company `id` number? hmmm, both id's are set to auto and primary keys.
Also, i made a company_id and thought of setting it up as a foreign key but I don't really understand foreign keys just yet... so do i need it right now?? or its something that i must have to connect both these tables to one user/member?
any help is appreciated!
thx