Reputation: 65
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 (username, password) VALUES (".$user.",'".$pass."')";
$query = mysql_query($sql);
if(!$query)
echo "Failed".mysql_error();
else
echo "Successful!";
?>
Upvotes: 1
Views: 4642
Reputation: 526
Your database credentials (root/no password) are invalid. Best solution would be to use phpMyAdmin to create a new user (preferably with a password) and use that user/password to connect.
Try replacing this line:
$sql = "INSERT into phplogin (username, password) VALUES (".$user.",'".$pass."')";
with this:
$sql = "INSERT into phplogin (username, password) VALUES ('".$user."','".$pass."')";
Upvotes: 1