$servername = 'edited';
$username = 'edited';
$password = 'edited';
$dbname = 'edited';

$name = $_POST ['name'];
$email = $_POST ['email'];
$number = $_POST ['number'];
$manufacturer = $_POST ['manufacturer'];
$birth = $_POST ['birth'];

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
echo "Connected successfully";

$sql = mysqli_query($conn, "INSERT INTO hgcasestudy (name, email, number, phonename, birthday) VALUES ($name, $email, $number, $manufacturer, $birth)");
if (!$sql) {
    die('Invalid query: ' . mysql_error());


I keep getting the error message: Connected successfullyInvalid query: Access denied for user 'edited'@'localhost' (using password: NO)

I'm confused because $servername is not set to local? I think it's just out of syntax with other parts of the page. Any ideas? Many thanks.


You've mixed MySQL with MySQLi which is never going to work. You connected using MySQLi then tried to do a query using MySQL. Your query should be:

$sql = mysqli_query($conn,"INSERT INTO hgcasestudy (name, email, number, phonename, birthday) VALUES ($name, $email, $number, $manufacturer, $birth)");

It should also be pointed out that you are vulnerable to injection attacks by using form values without ANY checking or sanitizing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.