Created
July 3, 2024 21:36
-
-
Save Slaver/36db3eb0ed9a3aa3697cac8bf63506c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class UserManager | |
{ | |
private $db; | |
public function __construct($db) | |
{ | |
$this->db = $db; | |
} | |
public function createUser($username, $email, $password) | |
{ | |
$query = "INSERT INTO users (username, email, password) VALUES ('$username', '$email', '$password')"; | |
$result = mysql_query($query); | |
if ($result) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
public function getUserByEmail($email) | |
{ | |
$query = "SELECT * FROM users WHERE email = '$email'"; | |
$result = mysql_query($query); | |
if (mysql_num_rows($result) > 0) { | |
return mysql_fetch_assoc($result); | |
} else { | |
return null; | |
} | |
} | |
public function updateUserPassword($userId, $newPassword) | |
{ | |
$query = "UPDATE users SET password = '$newPassword' WHERE id = $userId"; | |
return mysql_query($query); | |
} | |
} | |
// Run | |
$userManager = new UserManager($db); | |
$user = $userManager->getUserByEmail('example@email.com'); | |
if ($user) { | |
echo "User found: " . $user['username']; | |
} else { | |
echo "User not found"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment