An error while submitting the form
robert7045
Posted on January 25, 2023
I'm having issues with my code and was hoping someone could help me out. I'm trying to How Should Work Boots Fit create a simple login form for my website about teaching laptops and facial treatment benefits using PHP and MySQL, but I keep getting an error when I try to submit the form. Here is the error message I'm receiving:
'Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: YES) in /var/www/html/login.php on limousine service Denver in line 10'.
Here is the APM Test code, I'm using:
<?php
// Connect to the MySQL database
$db = mysql_connect('localhost', 'root', 'password');
if (!$db) {
die('Could not connect: ' . mysql_error());
}
// Select the database
mysql_select_db('users', $db);
// Check if the form has been submitted
if (isset($_POST['submit'])) {
// Escape the user input to prevent SQL injection attacks
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
// Query the database to check if the user exists
$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$result = mysql_query($query);
// If a result is returned, the user is logged in
if (mysql_num_rows($result) == 1) {
// Start a session and redirect to the dashboard
session_start();
$_SESSION['username'] = $username;
header('Location: dashboard.php');
} else {
// If the user doesn't exist, display an error message
echo "Invalid username or password.";
}
}
?>
I've tried a few different things to fix this issue, but nothing seems to be working. I've checked to make sure that my MySQL username and password are correct, and I've also tried connecting to the database using mysql_connect() with and without the password parameter. I'm not sure what else to try.
Does anyone have any ideas on snorkeling mask how I can fix this issue? Any help would be greatly appreciated. Thank you!
Posted on January 25, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024