简体   繁体   中英

I am getting errors in php

I am getting this error and I have done everything I can think about. Can someone help me out I have been working on this all day. I am still a little newbie at it. Thanks.

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'username'@'localhost' (using password: YES) in C:\\wamp\\www\\member-form.php on line 81 error on connect

else{
$hostname="localhost";
$database="contact";
$mysql_login="username";
$mysql_password="password";

81.if (!($db = mysql_connect($hostname, $mysql_login , $mysql_password))){
    echo "error on connect";
}
else{
if (!(mysql_select_db($databse, $db))){
    echo mysql_error();
    echo "<br>error on table connection";
}
else{
    $SQL="Insert into tblUsers(username,password,firstname,lastname,email,address,city,state,zip, phone,signupDate)values)'".$_POST['username']."',PASSWORD('".$_POSR['password1']."'),'".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['address']."','".$_POST['city']."','".$_POST['state']."','".$_POST['zip']."','".$_POST['phone']."',NOW())";
    mysql_query($SQL);
    if (is_numeric(mysql_insert_id())){
        header("Location:member-content.php?name=".$_POST['username']);
    }
    else{
        echo "Sorry, there was an errot.Please try again ot contact the administrator";
    }
    mysql_close($db);//closeing out connection,done for now
  }
   }
 }

?>

The mysql username or password in your some of your configuration file is incorrect. You should see what kind of code is on member-form.php line 81 as mentioned in the error.

Edit: Create a new file test.php and put following code in it, and see in your browser what you get:

<?php
mysql_connect("localhost", "Web_User", "my1230") or die(mysql_error());
echo "Connected to MySQL<br />";
?>

Please don't use mysql it isn't save and it is deprecated use mysqli or pdo. here below is an example for mysqli

$servername = "localhost";
$username = "root";
$password = "thisisthepassword";
$dbname = "exampledatabase";
$conn = mysqli_connect($servername, $username, $password, $dbname);

This means you have set the wrong password. Check wherever you set your config that your password has the right case, and no typos.

Your password is wrong for the user you are trying to login as.

The default WAMP username is "root" and password is blank.

mysql_connect("localhost","root");

If you go into your mySQL control panel, you can add users with passwords, and then add them to databases. You need to create a user, and then add that user to the database with ALL privileges. If you are using OS XI strongly suggest Sequel Pro to help simplify.

http://www.sequelpro.com/

If you don't have OS X there are plenty of other tools such as:

http://www.phpmyadmin.net/home_page/index.php

Now, once you do that (created a user), take the username and password and plug them into your script. The username is the username you just created and the password is the password associated with that user.

The error message tells you that you couldn't connect.

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