Click here to Skip to main content
15,609,498 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<?php

$YourName = $_POST['YourName'];
$Email = $_POST['Email'];
$Phone = $_POST['Phone'];
$Message = $_POST['Message'];

//database connection//

$conn = new mysqli('localhost','root','','jayinfo contact');
if($conn->connect_error){ 
    die('connection failed :'.$conn->connect_error);
}else{
    $stmt = $conn->prepare("insert into contact(YourName,Email,Phone,Message) values(?,?,?,?)");
    $stmt->bind_param("ssis",$YourName,$Email,$Phone,$Message);
    $stmt->execute();
    echo"Contact SUccessfully...";
    $stmt->close();
    $conn->close();
    
}


?>


What I have tried:

Q. Notice: Undefined variable: servername in C:\xampp\htdocs\Jayinfo\index.php on line 8 Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'jayinfo contact'@'localhost' (using password: NO) in C:\xampp\htdocs\Jayinfo\index.php on line 8 Connection failed: Access denied for user 'jayinfo contact'@'localhost' (using password: NO) this error i got.


I got this error I cant connect html form to databse.





I search on YouTube, Google and friend circle but I couldn't get this problem solution please give me a solution.
Posted
Comments
Richard MacCutchan 7-Feb-21 14:05pm    
The error message do not seem to match the code you have posted.
Maciej Los 14-Feb-21 13:33pm    
Take a look at the documentation: PHP: mysql_connect - Manual[^]
mysql_connect accepts the following parameters:
1. -> server
2. -> username
3. -> password
Are you sure that password has to be an empty string?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900