Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Ben Quartermaine
Ben Quartermaine
14,966 Points

Connecting mySQL database

I'm having trouble setting up a connection to a phpMyAdmin database I have created. I am trying to create a sign up page. When a user enters their username and password I want the database to be updated. I'm getting the following error messages:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user: 'root@localhost' (Using password: NO) in W:\www\signup.php on line 2

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in W:\www\signup.php on line 3

Warning: mysql_query() [function.mysql-query]: Access denied for user: 'ODBC@localhost' (Using password: NO) in W:\www\signup.php on line 10

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in W:\www\signup.php on line 10 FailedAccess denied for user: 'ODBC@localhost' (Using password: NO)

Here is my code...

<?php
    $conn = mysql_connect("localhost","root","");
    $db   = mysql_select_db("loginpage", $conn);
?>

<?php
    $user = $_POST['n'];
    $pass = $_POST['p'];
    $sql = "INSERT into phplogin VALUES(".$user.",'".$pass."')";
    $query = mysql_query($sql);

    if(!$query)
        echo "Failed".mysql_error();
    else
        echo "Successful!";
?>

1 Answer