正如标题上所说,我很确定我已经定义了它,顺便说一句,我是 PHP 新手,所以任何人都可以帮助我,而且我很抱歉有些变量是用 bahasa 写的,但这不是问题所以.. .
我尝试了堆栈溢出在处理类似问题时提供的所有方法,但没有任何效果。
<?php
// Check existence of id parameter before processing further
if(isset($_GET["id"]) && !empty(trim($_GET["id"]))){
// Include config file
include "koneksi.php";
// Prepare a select statement
$sql ="SELECT tabel_barang.nama_barang, tabel_stock.quantity
FROM tabel_barang
LEFT JOIN tabel_stock ON tabel_barang.tabel_barang id=tabel_stock.tabel_stock id
ORDER BY tabel_barang.nama_barang";
if($stmt = mysqli_prepare($db, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "i", $param_id);
// Set parameters
$param_id = trim($_GET["id"]);
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
$result = mysqli_stmt_get_result($stmt);
if(mysqli_num_rows($result) == 1){
/* Fetch result row as an associative array. Since the result set contains only one row, we don't need to use while loop */
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
// Retrieve individual field value
$nama_barang = $row["nama_barang"];
$quantity = $row["quantity"];
} else{
// URL doesn't contain valid id parameter. Redirect to error page
header("location: error.php");
exit();
}
} else{
echo "Terjadi kesalahan, silahkan coba lagi.";
}
// Close statement
mysqli_stmt_close($stmt);
// Close connection
mysqli_close($db);
}
} else{
// URL doesn't contain id parameter. Redirect to error page
header("location: error.php");
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Check Data</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<style type="text/css">
.wrapper{
width: 500px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="page-header">
<h1>Check Data</h1>
</div>
<div class="form-group">
<label>Nama Barang</label>
<p class="form-control-static"><?php echo $row["nama_barang"]; ?></p>
</div>
<div class="form-group">
<label>Quantity</label>
<p class="form-control-static"><?php echo $row["quantity"]; ?></p>
</div>
<p><a href="stock.php" class="btn btn-primary">Kembali</a></p>
</div>
</div>
</div>
</div>
</body>
</html>
我希望数据会显示出来,但它给了我这样的错误报告
注意:未定义变量:第 85 行 C:\xampp\htdocs\test\transaksi_toko\read_stock.php 中的行
还有这个
注意:未定义变量:第 89 行 C:\xampp\htdocs\test\transaksi_toko\read_stock.php 中的行
如果我的信息或代码没有提供足够的信息,我很抱歉,这是我第一次在这个平台上提问。