简体   繁体   中英

Can't insert data into 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 (username, password) VALUES (".$user.",'".$pass."')";
    $query = mysql_query($sql);

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

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."')";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM