$host = "localhost";
  $user = "root";
  $pass = "";

  $databaseName = "foresight";
  $tableName = "userinfo";
  $con = mysql_connect($host,$user,$pass);
  $dbs = mysql_select_db($databaseName, $con);
  $result = mysql_query("SELECT * FROM $tableName where flag != 1");          //query
  $email = mysql_fetch_row($result);                          //fetch result    
  mysql_close( $con ); 
$connection = mysql_connect("","root","causealmedus-1608");
if (!$connection)
  die('Could not connect: ' . mysql_error());
mysql_select_db("foresight", $connection);

$sql="INSERT INTO userinfo ('email')
('" . $email['email'] . "')";
if (!mysql_query($sql,$connection))
  die('Error: ' . mysql_error());
echo $email;

 //and using connection of localhost you have to update same record with status 1 at localhost. 


i face the following error:Could not connect: No connection could be made because the target machine actively refused it. 

If the remote mysql server is running on linux, you must grant this user the permission as "GRANT ALL". Please consult the msyql documentation for this. If you are currently using a cpanel or WHM VPS manager, you can also set it there. Also on cpanel, there is also an option there under the mysql section.

I am not sure if this is valid IP "" for mysql connection though. If I can still recall it, it was something like this IP:PORT_NUMBER. It all depends on how the remote server was setup, your IP might be the only one needed. To find out more about this topic, please read it here.

Be a part of the DaniWeb community

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