What are the potential security risks of storing passwords in plain text in a PHP database?

Storing passwords in plain text in a PHP database poses a significant security risk as anyone with access to the database can easily view and misuse the passwords. To mitigate this risk, passwords should be securely hashed using a strong hashing algorithm like bcrypt before storing them in the database. This way, even if the database is compromised, the passwords are not easily readable or usable.

// Hashing the password before storing it in the database
$password = $_POST['password'];
$hashed_password = password_hash($password, PASSWORD_BCRYPT);

// Storing the hashed password in the database
$query = "INSERT INTO users (username, password) VALUES ('$username', '$hashed_password')";
// Execute the query