Hi guys i'm new to PHP, I have been doing a simple login system using php, and now I'm face with this error "Could not select database because Access denied for user ''@'localhost' to database 'loginsystem'"
to find out a little info about what is happening, change these bits of code:
Where you connect to the db :
mysql_connect("localhost","user","pass") or die(mysql_error());
Change pass to your password
Where you select the DB :
mysql_select_db("dbname") or die(mysql_error());
Change dbname to your dbname.
If you still get this error, run this SQL query in PHPMyAdmin, The MySQL Command Line tool, or any other thing that can run MySQL Commands:
It usually means you have provided invalid username and password into mysql_connect(). This may be because the user does not exist or the mysql server is currently down but when in doubt copy and paste the login details you last used for another site of yours on the same server (eg your master login).
i have a new error says, "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in checklogin.php on line 47
Wrong Username or Password"
this is a piece of my code:
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select database.
mysql_connect("localhost", "$username", "")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
//username, and password sent from form
// To protect MySQL injection (more detail about MySQL injection)
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM $tbl_name WHERE username'=$username' and password'=$password'";
// Mysql_num_row is counting table row
// If result matched $username and $password, table row must be 1 row
// Register $username, $password, and redirect to file "login_success.php"
echo "Wrong Username or Password";
<div class="content"><!--start of content -->
<h2 style="background-color: #FC0; text-align: left; font-family: verdana;">Welcome
$_SESSION['username'] = $result['username'];
<p class="smallp">Hello there! Thanks for visiting our website. We're looking forward to hear from you. We have a guestbook on
the left navigation bar so you can interact with us and tell and ask us about your visit on our website.
You are free to suggest and give us
reasonable feedbacks. We are proud B-Meg, Purina, and Pilmico retailer. Thus, you can be sure to have
your animals to feed quality products.</p>