Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use the same names (case sensitive) for database, table, fields, record data, an

ID: 3687670 • Letter: U

Question

Use the same names (case sensitive) for database, table, fields, record data, and file names (.php) because this determines if your work will run or not on a different computer.

I already have the database created. Need part two written in PHP.

1) Create a database with the following requirements:

- Name: userdb

- Table: usertb

- Fields: username, password

Add these 2 records to the table:

- userone, pwo

- usertwo, pwt

2) Write and test a function that has the following requirements:

- the function accepts 2 variables (username & password)

- the function connect to the database created in section 1 (above)

- the function returns true if the username exist in the database and matches its password else, it returns false

- remember to close the connection to the database before the return so other parts of this program will work properly

Explanation / Answer

1)

user@server:~$ mysql -u mysql_user -p
Enter password:

mysql > create database db_name;
mysql > show databases;
mysql > create user db_user;
mysql > grant all on db_name.* to 'db_user'@'localhost' identified by 'db_password';

2)

#include <iostream>
#include <string>

using namespace std;

int main( )
{
const string USERNAME = "user";
const string PASSWORD = "123456";
string username, password;
cout << "Enter Username : ";
cin >> username;
if(username.length( ) < 4)
{
cout << "Username length must be atleast 4 characters long.";
}
else
{
cout << "Enter Password : ";
cin >> password;
if(password.length( ) < 6)
{
cout << "Password length must be atleast 6 characters long.";
}
else
{
if(username == USERNAME && password == PASSWORD)
{
cout << "User credentials are correct!!!" << endl;
}
else
{
cout << "Invalid login details" << endl;
}
}
}

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote