note 129560 added to reserved.variables.server
| From: | Anonymous | Date: | Fri, 07 Jun 2024 02:25:20 +0000 |
| Subject: | note 129560 added to reserved.variables.server | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221362@lists.php.net to get a copy of this message | ||
<?php
// Database connection information
$servername = "localhost"; // The server name or IP address where the MySQL database is
hosted
$username = "_admin"; // The username to connect to the MySQL database
$password = "_2001_"; // The password associated with the MySQL username
$dbname = "customer"; // The name of the MySQL database to connect to
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname); // Establish a new connection to the
MySQL database
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error); // If the connection fails,
output an error message and terminate the script
}
// Get user inputs from the form and sanitize them
$customerID = $conn->real_escape_string($_POST['customerNum']); // Retrieve and
sanitize the customerID from the form input to prevent SQL injection
$status = $conn->real_escape_string($_POST['shipped']); // Retrieve and sanitize the
status from the form input to prevent SQL injection
// Build the SQL query based on user input
$sql = "SELECT p.orderID, p.orderDate, p.shippingDate, c.customerID, c.firstName, c.lastName,
c.postcode
FROM purchase p
JOIN customer c ON p.customerID = c.customerID
WHERE p.customerID = '$customerID'"; // Start building the SQL query to
retrieve orders for the specified customer
// Add condition for shipped status based on user selection
if ($status === 'Y') {
$sql .= " AND p.shipped = 'Y'"; // Append condition to the SQL query if the
user selected "Shipped"
} else if ($status === 'N') {
$sql .= " AND p.shipped = 'N'"; // Append condition to the SQL query if the
user selected "Not-shipped"
}
// Order the results by orderDate in ascending order
$sql .= " ORDER BY p.orderDate ASC"; // Append an ORDER BY clause to the SQL query to sort
the results by orderDate in ascending order
// Execute the query
$result = $conn->query($sql); // Execute the SQL query and store the result in the $result
variable
// Check if any results were returned
if ($result->num_rows > 0) {
// If there are results, display them in a table
echo "<table border='1'>"; // Start the HTML table and set the border
attribute
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>"; //
Output the table headers
// Fetch and display each row of the result set
while($row = $result->fetch_assoc()) { // Loop through each row in the result set
echo "<tr>"; // Start a new table row
echo "<td>" . $row['orderID'] . "</td>"; //
Display the orderID in a table cell
echo "<td>" . $row['orderDate'] . "</td>"; //
Display the orderDate in a table cell
echo "<td>" . $row['shippingDate'] . "</td>"; //
Display the shippingDate in a table cell
echo "<td>" . $row['customerID'] . "</td>"; //
Display the customerID in a table cell
echo "<td>" . $row['firstName'] . "</td>"; //
Display the firstName in a table cell
echo "<td>" . $row['lastName'] . "</td>"; //
Display the lastName in a table cell
echo "<td>" . $row['postcode'] . "</td>"; //
Display the postcode in a table cell
echo "</tr>"; // End the table row
}
echo "</table>"; // End the HTML table
} else {
// If there are no results, display a message
echo "No orders were found that match your criteria."; // Output a message indicating
that no orders were found
}
// Close the database connection
$conn->close(); // Close the connection to the MySQL database
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 1.145.122.183)
----
Manual Page -- https://php.net/manual/en/reserved.variables.server.php
Edit -- https://main.php.net/note/edit/129560
Del: integrated -- https://main.php.net/note/delete/129560/integrated
Del: useless -- https://main.php.net/note/delete/129560/useless
Del: bad code -- https://main.php.net/note/delete/129560/bad+code
Del: spam -- https://main.php.net/note/delete/129560/spam
Del: non-english -- https://main.php.net/note/delete/129560/non-english
Del: in docs -- https://main.php.net/note/delete/129560/in+docs
Del: other reasons-- https://main.php.net/note/delete/129560
Reject -- https://main.php.net/note/reject/129560
Search -- https://main.php.net/manage/user-notes.php