title: PHP SQL : How to save data to multiple database from one html form OR how to copy data from one database to another database automatically
body: <p>I have a html form, say example</p>
  
  <pre><code>&lt;form action="form.php" method="post"&gt;
  First name:&lt;br&gt;
  &lt;input type="text" id="fname" name="fname"&gt;
  &lt;br&gt;
  Last name:&lt;br&gt;
  &lt;input type="text" id="lname" name="lname"&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and form.php</p>
  
  <pre><code>&lt;?php
  $servername = "localhost";
  $username = "database1";
  $password = "xxxxxxxx";
  $dbname = "database1";
  
  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);
  // Check connection
  if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  }
  
  //escape variables for security
  $fname = mysqli_real_escape_string($conn, $_POST['fname']);
  $lname = mysqli_real_escape_string($conn, $_POST['lname']);
  
  $sql = "INSERT INTO mytable (fname,lname)
  VALUES ('$fname','$lname')";
  
  if ($conn-&gt;query($sql) === TRUE) {
     echo "Successfully Saved";
  
      } else {
      echo "Error: Go back and Try Again ! " . $sql . "&lt;br&gt;" . $conn-&gt;error;
  }
  
  $conn-&gt;close();
  
  ?&gt;
  </code></pre>
  
  <p>The form.php is saving that data to <code>database1</code> .</p>
  
  <p>I want that data to be saved to another database <code>database2</code> along with <code>database1</code>.</p>
  
  <p>Is it possible ?? If yes then what changes should be made in the code ?</p>
  
  <p>If it is not possible then is it possible to copy data from <code>database1</code> to <code>database2</code> automatically? Whenever a new row is added in <code>database1</code> then it should automatically copied to <code>database2</code>.</p>
  
  <p>I want the same data to be in two different database. How can I achieve any of the above said ??</p>