PHP ASSIGNMENT Hello, I’m having some issues finishing a simple fictitious busin
ID: 3917896 • Letter: P
Question
PHP ASSIGNMENT
Hello, I’m having some issues finishing a simple fictitious business site for an assignment. I have a SQL database to connect to, just need help in creating the PHP pages that will connect to it. If you can provide *extremely simple* HTML also, that would be appreciated. Probably looking at 4 pages total. Thank you in advance!
**So far, I can register a user name and password (all of which saves to the database), log in and take the user to a Dashboard**
I need to have the following (should also include some object-oriented programming):
1. Front-End: including a home page, log in page, details/product page AND a register page
2. Registration Form: Form that allows a user to sign in, after which they can access the admin/back-end
3. Details Page: this should display the data entered by the user
4. Back-end: password protected and only accessed after a user has registered and signed in. If someone is trying to access the Admin page, they should be redirected to the front/landing page if they are not signed-in.
5. Data Entry form: a part of the Back-end and only visible to registered users. Here, they would enter information about the services the fictitious business provides, like their automobile repair history, etc.
6. Edit, Update and Delete: the registered user should be able to perform these 3 tasks with their own entries
7. Managing State: the Back-end should remain accessible and visible to the user who is currently logged in. The user should be able to move between the front-end/back-end, using session variables to maintain state. When the user logs out, the Back-end is no longer available until they log back in.
8. Log-in and Log-out: there needs to be an indication that the user is logged in, such as a “Hi Guest” message BEFORE the user logs in and a “Hi Joe” message that stays persistent throughout the site. There also needs to be a log-out mechanism that will kill all session variables.
Explanation / Answer
<html>
<head>
<title>PHP PAGE</title>
</head>
<?php
session_start();
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$bool = true;
mysql_connect("localhost", "root", "") or die (mysql_error()); //Connect to server
mysql_select_db("first_db") or die ("Cannot connect to database"); //Connect to database
$query = mysql_query("Select * from users WHERE username='$username'"); // Query the users table
$exists = mysql_num_rows($query); //Checks if username exists
$table_users = "":
$table_password = "";
if($exists > 0) //IF there are no returning rows or no existing username
{
while($row = mysql_fetch_assoc($query)) // display all rows from query
{
$table_users = $row['username']; // the first username row is passed on to $table_users, and so on until the query is finished
$table_password = $row['password']; // the first password row is passed on to $table_password, and so on until the query is finished
}
if(($username == $table_users) && ($password == $table_password))// checks if there are any matching fields
{
if($password == $table_password)
{
$_SESSION['user'] = $username; //set the username in a session. This serves as a global variable
header("location: home.php"); // redirects the user to the authenticated home page
}
}
else
{
Print '<script>alert("Incorrect Password!");</script>'; // Prompts the user
Print '<script>window.location.assign("login.php");</script>'; // redirects to login.php
}
}
else
{
Print '<script>alert("Incorrect username!");</script>'; // Prompts the user
Print '<script>window.location.assign("login.php");</script>'; // redirects to login.php
}
?>
<body>
<h2>Home Page</h2>
<hello>!
<a href="login.php">"Hi Guest"</a><br/><br/>
<form action="add.php" method="POST">
Add more to list: <input type="text" name="details" /> <br/>
Public post? <input type="checkbox" name="public[]" value="yes" /> <br/>
<input type="submit" value="Add to list"/>
</form>
<h2 align="center">My list</h2>
<a href="logout.php">"Hi Joe"</a><br/><br/>
<form action="add.php" method="POST">
Add more to list: <input type="text" name="details" /> <br/>
Public post? <input type="checkbox" name="public[]" value="yes" /> <br/>
<input type="submit" value="Add to list"/>
</form>
<h2 align="center">My list</h2>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.