MySQL Forums
Forum List  »  General

Sending html form data from to mysql by xampp
Posted by: alex i
Date: December 18, 2023 01:42AM

When I Submit my HTML form it shows this message:

Fatal error: Uncaught mysqli_sql_exception: Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\Test\process.php:9 Stack trace: #0 C:\xampp\htdocs\Test\process.php(9): mysqli_connect('localhost', 'root', Object(SensitiveParameterValue), 'register') #1 {main} thrown in C:\xampp\htdocs\Test\process.php on line 9

I don't know what is causing it to not work, I have followed all the videos and tutorials to fix it but it still is not working. I have got APACHE and MySql turned on in the xampp control panel. do any of you know how to fix this?

PHP code:

<?php
if (isset($_POST["submit"])) {
$first_name = $_POST["first_name"];
$last_name = $_POST["last_name"];
$email = $_POST["email"];
$color = $_POST["color"];

if(!empty($first_name) && !empty($last_name) && !empty($email) && !empty($color)) {
$link = mysqli_connect('localhost', 'root', '', 'register');
if ($link==false) {
die(mysqli_connect_error());
}
$sql = "INSERT INTO users (first_name, last_name, email, color) VALUES('$first_name','$last_name','$email','$color')";

if (mysqli_query($link,$sql)) {
echo "Record inserted successfully";
} else {
echo "Something went wrong";
}
} else {
echo "Please Provide All Information";
}
}
?>


HTML code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML form</title>
</head>
<body>
<div class="container">
<form action="process.php" method="post">
<div class="form-group">
<input type="text" name="first_name" id="" placeholder="First Name...">
</div>
<div class="form-group">
<input type="text" name="last_name" id="" placeholder="Last Name...">
</div>
<div class="form-group">
<input type="email" name="email" id="" placeholder="Email...">
</div>
<div class="form-group">
<select name="color" id="">
<option value="">Choose Color</option>
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
</select>
</div>
<div class="form-group">
<input type="submit" value="Submit" name="submit">
</div>
</form>
</div>

</body>
</html>

Options: ReplyQuote


Subject
Written By
Posted
Sending html form data from to mysql by xampp
December 18, 2023 01:42AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.