note 128584 added to mysqli.query
| From: | "magnetokid dot " at main dot php dot net | Date: | Mon, 05 Jun 2023 05:11:12 +0000 |
| Subject: | note 128584 added to mysqli.query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220541@lists.php.net to get a copy of this message | ||
<?php
// Establishing the database connection
$servername = "your_servername";
$username = "your_username";
$password = "your_password";
$dbname = "databasename";
$conn = new mysqli($servername, $username, $password, $dbname);
// Checking the database connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Retrieving user input from the form
$customerNum = $conn->real_escape_string($_POST['customerNum']);
$shipped = $conn->real_escape_string($_POST['shipped']);
// Building the SQL query based on user input
$sql = "SELECT orderID, orderDate, shippingDate, customerID, firstName, lastName, postcode
FROM orders
WHERE customerID = '$customerNum'
AND shipped = '$shipped'
ORDER BY orderDate ASC";
// Executing the SQL query
$result = $conn->query($sql);
// Checking if any orders were found
if ($result->num_rows > 0) {
// Displaying the orders in a table
echo "<table>";
echo "<tr><th>Order ID</th><th>Order
Date</th><th>Shipping Date</th><th>Customer ID</th><th>First
Name</th><th>Last Name</th><th>Postcode</th></tr>";
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row["orderID"] . "</td>";
echo "<td>" . $row["orderDate"] . "</td>";
echo "<td>" . $row["shippingDate"] . "</td>";
echo "<td>" . $row["customerID"] . "</td>";
echo "<td>" . $row["firstName"] . "</td>";
echo "<td>" . $row["lastName"] . "</td>";
echo "<td>" . $row["postcode"] . "</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "No orders were found that match your criteria.";
}
// Closing the database connection
$conn->close();
?>
this is a php code that will do connections to a database and give display to tables. This can be
linked to a html file.
----
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/128584
Del: integrated -- https://main.php.net/note/delete/128584/integrated
Del: useless -- https://main.php.net/note/delete/128584/useless
Del: bad code -- https://main.php.net/note/delete/128584/bad+code
Del: spam -- https://main.php.net/note/delete/128584/spam
Del: non-english -- https://main.php.net/note/delete/128584/non-english
Del: in docs -- https://main.php.net/note/delete/128584/in+docs
Del: other reasons-- https://main.php.net/note/delete/128584
Reject -- https://main.php.net/note/reject/128584
Search -- https://main.php.net/manage/user-notes.php