php - Access denied for user - (using password: NO)


Hi I'm trying to connect to my database to use my registration form but im having no luck. When I run connection.php it displays the message: Access denied for user ''@'' (using password: NO)

any tips much appreciated :)


$servername = "";
$username = "c3438525_co_uk";
$password = "password";
$con=mysqli_connect("", "c3438525_co_uk", "password", "c3438525_co_uk");

if ($con->connect_error)
    die("Connection failed: " . $con7>connect_error);
echo "Connected Successfully";
mysql_select_db( 'c3438525_co_uk' ) or die(mysql_error());

and my registrationsubmit.php

<font face="ClearSans-Thin">
<font color="lightgray">


include 'registrationform.php';
include 'connection.php';

if (isset($_POST['regsubmit'])) {
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $username = $_POST['username'];
    $password = $_POST['password'];
    //Insert into database the values entered in the registration form.
    $query = "INSERT INTO users (FirstName, LastName, Username, Password) VALUES ("$firstname","$lastname", "$username", "$password")"  
  Echo "Registration Successful - Press the Home button to return to the homepage.";





You're mixing mysqli with functions from the old mysql extension. That doesn't work.
Since there has been no connection established via mysql_connect, the mysql extension tries to establish the default connect when mysql_select_db is called. Hence theuser ''@'' (using password: NO) message.
Remove all mysql_* functions and use only the mysqli versions.

Btw: in your second script (as posted) the query is not actually sent to the mysql server. But it's probably not the "real" script anyway, since it would cause a parse error because of the double-quotes within the dobule-quoted string literal.

But while you're at it, please also have a read of

People are also looking for solutions to the problem: php - Logical operators should be avoided (use || instead of 'or') sensiolabs insight


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.