$conn = mysqli_connect($servername, $username, $password, $dbname);
$conn->set_charset("utf8");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$showitem = "SELECT id, name, brand, cat,mojodi,q1,q2,q3,qk,shk,foroshandeh,forokhteh FROM anbar2";
$result = $conn->query($showitem);
if ($result->num_rows > 0) {
echo "<table id='anbar'><tr><th>نام کالا</th><th>برند</th><th>دسته بندی</th><th>موجودی</th><th>فروخته شده</th><th>قیمت یک</th><th>قیمت دو</th><th>قیمت سه</th><th>قیمت خرید</th><th>شرایط خرید</th><th>فروشنده</th><th>کد</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["name"]."</td><td>".$row["brand"]."</td><td>".$row["cat"]."</td><td>".$row["mojodi"]."</td><td>".$row["forokhteh"]."</td><td>".$row["q1"]."</td><td>".$row["q2"]."</td><td>".$row["q3"]."</td><td>".$row["qk"]."</td><td>".$row["shk"]."</td><td>".$row["foroshandeh"]."</td><td>".$row["id"]."</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
if(isset($_POST['submit']))
{
echo "<meta http-equiv='refresh' content='0'>";
}
$sql = "UPDATE anbar2 SET name='$name',brand='$brand',mojodi=$mojodi+mojodi,q1=$q1,q2=$q2,q3=$q3,qk=$qk,shk='$shk',foroshandeh='$foroshandeh' WHERE id=$id ";
if (mysqli_query($conn, $sql)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
}