Friday 27 September 2013

Submit record in 2 databases

Submit record in 2 databases

I have a form and I want to submit the form data in 2 databases. But the
problem is: both the databases are on different servers. I am new to mysql
so I don't know exactly how to do that. I am working in php. I am sharing
my code with you, its not working properly. so please check this out:
$con = mysql_connect('differenthost','user1','pass1');
mysql_select_db('dbname1',$con);
$path = "misc/classified/".$submiturl;
mysql_query("insert into tablename1
(title,description,status,parent_id,path) values
('$submiturl','$submiturl','active','68','$path')") or
die(mysql_error());
mysql_close($con);
mysql_connect('localhost','user2','pass2');
mysql_select_db('dbname2');
$check = mysql_query("select count(*) from tablename2 where userid
= '".$_SESSION['userid']."' and datecreated = '$datecreated'") or
die(mysql_error());
This error comes when I submit the form:
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server
host 'differenthost' (25) in
/home/class/public_html/microworker/submiturl.php on line 11
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link
resource in /home/class/public_html/microworker/submiturl.php on line 12
Warning: mysql_query() [function.mysql-query]: Access denied for user
'user2'@'localhost' (using password: NO) in
/home/class/public_html/microworker/submiturl.php on line 16
Warning: mysql_query() [function.mysql-query]: A link to the server could
not be established in /home/class/public_html/microworker/submiturl.php on
line 16
Access denied for user 'user2'@'localhost' (using password: NO)
Please help me in that case, what is the right syntax?

No comments:

Post a Comment