<?php 
  $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 ); 
  ?>
  <?php
$connection = mysql_connect("192.232.240.245","root","causealmedus-1608");
if (!$connection)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("foresight", $connection);
while($email)
{

$sql="INSERT INTO userinfo ('email')
VALUES
('" . $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. 

 }



mysql_close($con)
?>
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 "192.232.240.245" 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, networking, learning, and sharing knowledge.