Can you help me with this program?. I am trying to insert data into two mysql tables at once. I have two tables: property and personal.

<?php
define('DB_NAME', 'purchase');
define('DB_USER', 'root');
define('DB_PASSWORD', 'root');
define('DB_HOST', 'localhost');

$connection = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if (!$connection) {
    die('Could not connect: ' . mysql_error());
}

$result = mysql_select_db(DB_NAME, $connection);

if (!$result) {
    die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}

echo 'Connected successfully';

$typepay = $_POST['typepay'];

$buyertype = $_POST['buyertype'];


$sql = "INSERT INTO property (typepay)". 
"VALUES". 
"('$typepay')";


$sql = "INSERT INTO personal". 
"(buyertype)". 
"VALUES". 
"('$buyertype')";



if (!mysql_query($sql)) {
    die('Error: ' . mysql_error());
}

mysql_close();

?>

Thank for the answers. :)

Line 31 overwrites line 26. In between you should have what's on line 38.

I did that but the data is only accessing the property table.

Do you get an error?

hey!it's working.thank you so much.you save my brain from exploding! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.