Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- form.html
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Update User</title>
- </head>
- <body>
- <h2>Update User Information</h2>
- <form action="update_user.php" method="post">
- <input type="hidden" name="id" value="1"> <!-- Assuming we want to update user with ID 1 -->
- <label for="name">Name:</label>
- <input type="text" id="name" name="name" required>
- <br><br>
- <label for="email">Email:</label>
- <input type="email" id="email" name="email" required>
- <br><br>
- <input type="submit" value="Update User">
- </form>
- </body>
- </html>
- updare_user.php
- <?php
- // Database credentials
- $host = 'localhost';
- $username = 'root';
- $password = '';
- $dbname = 'WT';
- // Create connection
- $conn = mysqli_connect($host, $username, $password, $dbname);
- // Check connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
- // Check if form data is submitted
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- // Get user ID, name, and email from form input
- $id = $_POST['id'];
- $name = $_POST['name'];
- $email = $_POST['email'];
- // Prepare the SQL query
- $sql = "UPDATE users SET username = '$name', email = '$email' WHERE id = $id";
- // Execute the query
- if (mysqli_query($conn, $sql)) {
- echo "User updated successfully";
- } else {
- echo "Error updating user: " . mysqli_error($conn);
- }
- }
- // Close the connection
- mysqli_close($conn);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement