note 128586 added to mysqli.query
| From: | heartbreakman at main dot php dot net | Date: | Mon, 05 Jun 2023 05:44:46 +0000 |
| Subject: | note 128586 added to mysqli.query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220543@lists.php.net to get a copy of this message | ||
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Q</title>
</head>
<body>
<h1>Q</h1>
<?php
// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Retrieve the minimum stock quantity entered by the user
$minimum = $_POST["minimum"];
// Validate that the minimum stock quantity is a positive integer
if (ctype_digit($minimum) && $minimum > 0) {
// Connect to the database
$dbConn = new mysqli('localhost', 'your_username',
'your_password', 'your_database');
// Check the database connection
if ($dbConn->connect_error) {
die('Connection error (' . $dbConn->connect_errno . ') ' .
$dbConn->connect_error);
}
// Prepare the SQL query to fetch products with quantity in stock greater than or equal to the
minimum
$sql = "SELECT product_code, product_name, quantity_in_stock FROM your_table WHERE
quantity_in_stock >= $minimum";
// Execute the query
$result = $dbConn->query($sql);
// Check if any results are found
if ($result->num_rows > 0) {
// Display the product details in a table
echo "<table>";
echo "<tr><th>Product Code</th><th>Product
Name</th><th>Quantity in Stock</th></tr>";
// Fetch and display each product row
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row["product_code"] . "</td>";
echo "<td>" . $row["product_name"] . "</td>";
echo "<td>" . $row["quantity_in_stock"] .
"</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "No products found with the minimum stock quantity.";
}
// Close the database connection
$dbConn->close();
} else {
echo "Please enter a valid positive integer for the minimum stock quantity.";
}
}
?>
</body>
</html>
This is another method of getting information from a SQL database using php.
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.130 (proxied: 163.53.144.71)
----
Manual Page -- https://php.net/manual/en/mysqli.query.php
Edit -- https://main.php.net/note/edit/128586
Del: integrated -- https://main.php.net/note/delete/128586/integrated
Del: useless -- https://main.php.net/note/delete/128586/useless
Del: bad code -- https://main.php.net/note/delete/128586/bad+code
Del: spam -- https://main.php.net/note/delete/128586/spam
Del: non-english -- https://main.php.net/note/delete/128586/non-english
Del: in docs -- https://main.php.net/note/delete/128586/in+docs
Del: other reasons-- https://main.php.net/note/delete/128586
Reject -- https://main.php.net/note/reject/128586
Search -- https://main.php.net/manage/user-notes.php