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:

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) {
$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">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML form</title>
<div class="container">
<form action="process.php" method="post">
<div class="form-group">
<input type="text" name="first_name" id="" placeholder="First Name...">
<div class="form-group">
<input type="text" name="last_name" id="" placeholder="Last Name...">
<div class="form-group">
<input type="email" name="email" id="" placeholder="Email...">
<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>
<div class="form-group">
<input type="submit" value="Submit" name="submit">


Options: ReplyQuote

Written By
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.