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

932

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 ''@'10.246.64.24' (using password: NO)

any tips much appreciated :)

connection.php:

<?php
$servername = "c3438525.co.uk.mysql";
$username = "c3438525_co_uk";
$password = "password";
ob_start();
$con=mysqli_connect("c3438525.co.uk.mysql", "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">

<?php

include 'registrationform.php';
include 'connection.php';
?>

<?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.";

}
?>
</center>   
762

Answer

Solution:

mysqli_connect(...
mysql_select_db('c3438525_co_uk'

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 ''@'10.246.64.24' (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 http://docs.php.net/security.database.sql-injection

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

Source

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.