Hi,
I am having some difficulty updating results in two MySQL tables (clients and addresses). Basically the client table holds results such as; client name, email address, telephone number etc and the addresses table holds the address of that client; city, post code, address etc.
The client table has a the primary key 'client_id' and the foreign key 'address_id'. The addresses table has the primary key 'address_id'.
I have built one form that uses the $_GET function to get results out of both of the tables, however, it only retrieves results out of the client table. Here is where I declare the variables for the script and use the UPDATE statement.
I am sure it is incorrect as it is not working. I am a PHP / MySQL newbie so any advice would be much appreciated.
$client_name = $_POST['client_name'];
$client_from_date = $_POST['client_from_date'];
$client_email = $_POST['client_email'];
$client_contact_name = $_POST['client_contact_name'];
$telephone = $_POST['telephone'];
$address_line_1 = $_POST['address_line_1'];
$address_line_2 = $_POST['address_line_2'];
$address_line_3 = $_POST['address_line_3'];
$town_city = $_POST['town_city'];
$county_region = $_POST['county_region'];
$post_code = $_POST['post_code'];
$project_count = $_POST['project_count'];
$billings_to_date = $_POST['billings_to_date'];
$no_projects_count = $_POST['no_projects_count'];
$client_id = $_POST['client_id'];
$address_id = $_POST['address_id'];
$sql_update = "UPDATE clients, addresses SET client_name = '" . $client_name ."', client_from_date = '" . $client_from_date . "', client_email = '" . $client_email . "', client_contact_name = '" .$client_contact_name . "', telephone = '" . $telephone . "', project_count = '" . $project_count . "', billings_to_date = '" . $billings_to_date . "', no_projects_count = '" . $no_projects_count . "', address_line_1 = '" . $address_line_1 . "', address_line_2 = '" . $address_line_2 . "', address_line_3 = '" . $address_line_3 . "', town_city = '" . $town_city . "', county_region = '" . $county_region . "', post_code = '" . $post_code . "' WHERE clients.address_id = '" . $address_id . "' AND addresses.address_id = '" . $address_id . "'";
mysql_query($sql_update);
$clients_addresses_join = mysql_query("SELECT * FROM clients INNER JOIN addresses ON clients.client_id = addresses.address_id")
or die(mysql_error());
header('location: ' . $_SERVER['PHP_SELF']);
break;