I need to enter data from a single html form in two tables which are created in two different databases, and I need to do this on single submit any suggestions what can be done for achieving this.
I have the following code:
<?php
echo "Entering";
$one= mt_rand(1000000000,9999999999);
$two= mt_rand(1000,9999);
echo "<br><br>getting values";
$user= mt_rand(1000000000,9999999999);
$useralias = $one.$two;
$first= $_POST['first_name'];
$last= $_POST['last_name'];
$email=$_POST['email'];
$country=$_POST['country'];
$city = $_POST['city'];
$zipcode = $_POST['zipcode'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$website= $_POST['website'];
$company= $_POST['company'];
echo $first;
echo "<br>".$last;
echo "<br><br>setting database etc one";
$host = "localhost";
$database = "mya2billing";
$table = "cc_card";
$username = "root";
$password = "mehusnain";
echo "<br><br>executing query one";
$con = mysql_connect($host , $username, $password );
if(!$con){
echo "Connection failed";
}
else{
mysql_select_db($database);
$query = "INSERT INTO $table (username, useralias, firstname, lastname, email, country, city, zipcode, address, phone, fax, company_name, company_website) VALUES ('$user','$useralias','$first','$last','$email','$country','$city','$zipcode','$address','$ phone','$fax','$website','$company')";
echo $query;
if(mysql_query($query)){
echo "<br><br>Insertion done in $table";
$con.close();
}
else{
echo "<br><br>Failed in $table";
$con.close();
}
}
echo "<br><br>setting databse 2 etc";
$host = "localhost";
$database = "voixe";
$table = "hak_users";
$username = "root";
$password = "mehusnain";
echo "<br><br>executing query 2";
$con = mysql_connect($host , $username, $password );
if(!$con){
echo "Connection failed";
}
else{
mysql_select_db($database);
$query = "INSERT INTO $table (user_login, user_pass, user_nicename, user_email, display_name) VALUES ('$user','password','$first." ".$last','$email','$first')";
echo $query;
if(mysql_query($query)){
echo "<br><br>Insertion done in $table";
$con.close();
}
else{
echo "
Failed in $table";
$con.close();
}
}
?>
One thing more that is not a single echo statement is working.....