I have already asked this question and received the below code but
I have already asked this question and received the below code but
I still can not connect to the database. It just tells me “Can not use school as the current database:” I have my table made and know that it has information. Can someone explain why I am not getting past the “Can not use school as current database:”
CREATE TABLE UserName ( UserNameID int(9) NOT NULL auto_increment, userName VARCHAR(40) NOT NULL, pass VARCHAR(40) NOT NULL, PRIMARY KEY(UserNameID) );
<?php
//connect to the database
$databaseHost = ‘localhost’;
$databaseName = ‘UserName’;
$databaseUsername = ‘root’;
$databasePassword = ‘root’;
$query = mysqli_connect(‘localhost’, ‘root’, ‘root’);
if (!$query) {
die(‘Not connected : ‘ . mysqli_error());
}
// make school the current db
$db_selected = mysqli_select_db(‘UserName’, $link);
if (!$db_selected) {
die (‘Can not use school as the current database: ‘ . mysqli_error());
}
//login to the system using the credentials provided by the user
//we start by obtaining the values as input by the user from the form
$user_name = mysqli_real_escape_string($_REQUEST[‘u_name’]);
$password = mysqli_real_escape_string($_REQUEST[‘pwd’]);
//we then retrieve what is actually stored in the database
$sql = “SELECT * FROM UserName WHERE userName= ‘”.$user_name.”‘ and password='”.$password.”‘”;
$r_query = mysqli_query($sql);
while ($row = mysqli_fetch_array($r_query)){
$user=$row[‘username’];
$pass=$row[‘password’];
}
//we then compare to see if the user data matches what is in the DB.
//If Yes, we log them in
if($user_name.equals($user) && $password.equals($pass)){
echo”logged in!”;
}
else{
echo”wrong username or passsword”;
}
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"
