<?php
include "connect.php";
$username = "huyna";
$sql = "SELECT * FROM users WHERE username = ?";
// Prepare the statement
$stmt = $conn->prepare($sql);
// Check if the statement is prepared successfully
if ($stmt) {
// Bind the value to the parameter
$stmt->bind_param("s", $username);
// Execute the statement
$stmt->execute();
// Get the result of the statement
$result = $stmt->get_result();
// Check if any records are found
if ($result->num_rows > 0) {
// Loop through each record and display the data
while ($row = $result->fetch_assoc()) {
echo "ID: " . $row["id"] . "<br>";
echo "Username: " . $row["username"] . "<br>";
echo "Password: " . $row["password"] . "<br>";
echo "Level: " . $row["level"] . "<br>";
echo "<br>";
}
} else {
echo "No records found!";
}
// Close the statement
$stmt->close();
} else {
echo "Failed to prepare statement!";
}
// Close the connection
$conn->close();
<?php
include "connect.php";
$username = 'abc';
$sql = "DELETE FROM users WHERE username = ?";
// Prepare the statement
$stmt = $conn->prepare($sql);
// Check if the statement is prepared successfully
if ($stmt) {
// Bind the value to the parameter
$stmt->bind_param("s", $username);
// Execute the statement
if ($stmt->execute()) {
echo "Record deleted successfully!";
} else {
echo "Failed to delete record!";
}
// Close the statement
$stmt->close();
} else {
echo "Failed to prepare statement!";
}
// Close the connection
$conn->close();