note 128587 added to mysqli.query

From: Date: Mon, 05 Jun 2023 05:49:30 +0000
Subject: note 128587 added to mysqli.query
Groups: php.notes 
Request: Send a blank email to php-notes+get-220544@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) { // Set up the database connection $hostname = 'localhost'; $username = 'your_username'; $password = 'your_password'; $dbname = 'your_database'; // Create a new mysqli instance $dbConn = new mysqli($hostname, $username, $password, $dbname); // 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> The code I have updated with the username required. ---- 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/128587 Del: integrated -- https://main.php.net/note/delete/128587/integrated Del: useless -- https://main.php.net/note/delete/128587/useless Del: bad code -- https://main.php.net/note/delete/128587/bad+code Del: spam -- https://main.php.net/note/delete/128587/spam Del: non-english -- https://main.php.net/note/delete/128587/non-english Del: in docs -- https://main.php.net/note/delete/128587/in+docs Del: other reasons-- https://main.php.net/note/delete/128587 Reject -- https://main.php.net/note/reject/128587 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220544) next »