0

I just created a code that copies data from one table to another and deletes it from the original table.

My code is running when I'm using XAMPP, but shows error when I deploy to hosting server.

Here's my code:

<?php
include "../../database.php";

$coldstorage = $_POST['coldstorage'];

$status = 0;

date_default_timezone_set('Asia/Jakarta');
$date = date('Y-m-d H:i:s');

$sql = "SELECT * FROM datacoldstorage WHERE id = '$coldstorage'";
$result = mysqli_query($db, $sql);
$row = mysqli_fetch_array($result);
$importir = $row['importir'];
$merek = $row['merek'];
$jenisdaging = $row['jenisdaging'];
$qty = $row['qty'];
$hargadasar = $row['hargadasar'];
$hargaaset = $row['hargaaset'];
$operator = $row['operator'];
$foto = $row['foto'];

$sql = "INSERT INTO tempcoldstorage (tanggalwaktu, importir, merek, jenisdaging, qty, hargadasar, hargaaset, operator, foto, status) VALUES ('$date', '$importir', '$merek', '$jenisdaging', '$qty', '$hargadasar', '$hargaaset', '$operator', '$foto', '$status')";
$result = mysqli_query($db, $sql);

if($result){
    $sql = "DELETE FROM datacoldstorage WHERE id = '$coldstorage'";
    $result = mysqli_query($db, $sql);
    if($result){
        echo "<script>alert('Data berhasil di input'); window.location.href='produksi.php';</script>";
    }
}

I don't know what should I do now.

matronator
  • 465
  • 6
  • 13
  • 3
    Pls enable error reporting, then tell us what exact error(s) the system shows – Ken Lee Sep 10 '22 at 11:00
  • Have you checked in the inspector to see for any errors in the console tab or what php is calling in the network tab? – dreid Sep 10 '22 at 11:01
  • there is no any error message in log and console, everything just blank, I really confused – Nikolai Harkov Sep 10 '22 at 11:03
  • Comment out all the code. Remove comment one step at a time. Check result. repeat. Start with printing out the $coldstorage variable. – rgucluer Sep 10 '22 at 11:26
  • 1
    If `$result` is false there is no output so there could be no error but failing query. Use error reporting as already stated. This also is open to SQL injections (which could be the issue) parameterize query and use prepared statements. – user3783243 Sep 10 '22 at 11:33

0 Answers0