Insert data into database MySQL Laptop lain

Saya mempunyai data array yang diambil dari mesin finger print, data tersebut berhasil ditampilkan dilaptop saya. Data array tersebut juga sudah berhasil di INSERT INTO database di localhost laptop saya,ย 

Tetapi jika saya ingin memasukkan data tersebutย  ke PHPMyAdmin di laptop lain menggunakan IP laptop tersebut tidak berhasil.ย 

Test PING ke IP Laptop tersebut berhasil.
Memanggil IP Laptop tersebut di Web browser dan masuk kedalam PHPMyAdmin laptopnya juga berhasil, saya juga sudah membuat DB dan tabel yang sama melalui web browser saya yang memanggil IP Laptop tersebut.

Sepertinya saya butuh bantuan untuk script koneksinya.
<?php

require 'zklibrary.php';

$zk = new ZKLibrary("192.168.1.201", 4370); //IP mesin Finger Print
$zk->connect();
$zk->disableDevice();

//$nama = $zk->getUser();
$users = $zk->getAttendance();
////////////////////////////

//var_dump($users);

?>
<table width="100%" border="1" cellspacing="0" cellpadding="0" style="border-collapse:collapse;">
  <thead>
    <tr>
      <td width="25">No</td>
      <td>UID</td>
      <td>ID</td>
      <td>Name</td>
      <td>Role</td>
      <td>Password</td>
  	  <td>Password</td>
  	  <td>Password</td>
    </tr>
  </thead>
<tbody>


<?php
//koneksi database localhost
$hostname = 'localhost';
$username = 'root';
$password = 'rootroot';
$database = 'db_fp';

$connection = mysqli_connect($hostname, $username, $password, $database);
if (!$connection){
        die("Connection Failed:".mysqli_connect_error());
    }
///////////////////////////////

//koneksi ke database dilaptop lain
$hostname1 = '192.168.0.107'; //IP Laptop lain yang dituju
$username1 = 'root';
$password1 = 'rootroot';
$database1 = 'db_fp';

$connection1 = mysqli_connect($hostname1, $username1, $password1, $database1);
if (!$connection1){
        die("Connection Failed:".mysqli_connect_error());
    }
///////////////////////////////
?>


<?php
$no = 0;
foreach($users as $key => $user)
{

  $uid = $user[0];
  $id = $user[1];
  $state = $user[2];
  $time = $user[3];
  $query= mysqli_query($connection1, "SELECT * FROM person where uid = '$uid'");
  if(mysqli_num_rows($query)==0){
      $sql = mysqli_query($connection, "insert into person(uid, id, state, time) values  ('$uid', '$id', '$state', '$time')"); // INSERT INTO DB di LOCALHOST
      $Sql1 = mysqli_query($connection1, "insert into person(uid, id, state, time) values  ('$uid', '$id', '$state', '$time')"); //INSERT INTO DB di Laptop Lain
  }

  $no++;
  ?>
  <tr>
    <td align="right"><?php echo $no; ?></td>
    <td><?php echo $key; ?></td>
    <td><?php echo $user[0]; ?></td>
    <td><?php echo $user[1]; ?></td>
    <td><?php echo $user[2]; ?></td>
    <td><?php echo $user[3]; ?></td>
	  <td><?php echo $user[4]; ?></td>
	  <td><?php echo $user[5]; ?></td>
    
  </tr>
  <?php
}
?>
</tbody>
</table>


<?php
$zk->enableDevice();
$zk->disconnect();

?>

avatar barkah03

@barkah03

19 Kontribusi 4 Poin


Jawaban

Coba baris ini :
$Sql1 = mysqli_query($connection1, "insert into person(uid, id, state, time) values  ('$uid', '$id', '$state', '$time')"); //INSERT INTO DB di Laptop Lain

di tambahin jadi gini :
$Sql1 = mysqli_query($connection1, "insert into person(uid, id, state, time) values  ('$uid', '$id', '$state', '$time')");
if(!$Sql1){
   echo mysqli_error($connection1) . "<br>";
}

Tujuannya agar ketika ada kesalahan query, error-nya keliatan dimana.
avatar ahanafi

@ahanafi

614 Kontribusi 357 Poin


Login untuk gabung berdiskusi