miércoles, 12 de abril de 2023

C3 - Web Applications for Everybody Specialization - COURSE 3

 Building Database Applications in PHP

LECTURES COURSE 3

Subscribe to more Courses.
COLLABORATOR CHANNELS
YOUCOURSE - COURSES FROM BEST UNIVERSITYS IN THE WORLD - https://www.youtube.com/@YouCourse
ARQUITECTURAS - ARCHITECTURE CHANNEL, DOCUMENTALS AND MORE - https://www.youtube.com/@ArquitecturasYT
CADESIGNERS - SOFTWARE CHANNEL AND MODELS - https://www.youtube.com/@CADesigners
UNDERGROUND - Subscribe! Free Music - Creative Commons - https://www.youtube.com/@UndergroundMC

FACEBOOK GROUPS
ARQUITECTURAS - ARCHITECTURE CHANNEL - https://www.facebook.com/groups/arquitecturasyt
YOUCOURSE - COURSES FROM BEST UNIVERSITYS IN THE WORLD - https://www.facebook.com/groups/youcourse/
CADESIGNERS - SOFTWARE DESIGN CHANNEL - https://www.facebook.com/groups/cadesignersyt
UNDERGROUND - Free Music - Creative Commons - https://www.facebook.com/groups/undergroundyt

Facebook - https://www.facebook.com/YouCourseYT
Twitter - https://twitter.com/YouCourseYT
Tik Tok - https://www.tiktok.com/@youcourseyt
Kwai - YouCourse - @yourcourse

Thank's For Support!

WEEK 1 - PHP Objects
We look at the object oriented patterns available in PHP.
00:00 - Welcome to the Course
3:06 - Object Oriented Concepts
15:25 - Creating Objects in PHP
23:04 - Object Oriented Libraries in PHP
29:28 - Object Life Cycle in PHP
34:37 - Object Inheritance in PHP
43:53 - Installing MAMP on Macintosh
50:36 - Installing MAMP on Windows10
1:04:57 - Installing XAMPP on Windows10
1:14:03 - Windows: Using NGrok with the Autograder
1:19:07 - Macintosh: Using NGrok with the Autograder
1:28:44 - Bonus: Office Hours New York City

WEEK 2 - Connecting PHP and MySQL
We look at how we connect to a MySQL using the Portable Data Objects (PDO) library and issue SQL commands in the the PHP language.
1:33:30 - PHP Database Libraries
1:40:56 - Running SQL Queries in PHP
1:52:40 - Accessing MySQL Using PDO: Inserting Data
2:02:51 - Security Issue: Avoiding SQL Injection
2:12:08 - Error Handling with PDO
2:20:20 - Code Walkthrough - PHP, MySQL, and PDO
2:28:54 - Code Walkthrough - Inserting and Deleting Data
2:38:18 - Code Walkthrough - Security and SQL Injection
2:46:09 - Bonus: Office Hours Orem, Utah

WEEK 3 - PHP Cookies and Sessions
We look at how PHP uses cookies and manages session data.
2:47:46 - Cookies
2:55:38 - Sessions
3:06:18 - Sessions Without Cookies
3:10:56 - Code Walkthrough - Cookies and Sessions
3:21:11 - Bonus: Office Hours, Detroit, Michigan

WEEK 4 - PHP Redirect, Routing, and Authentication
We look at how PHP avoids double posting data, how flash messages are implemented, and how we use a session to log in users in web applications.
3:22:45 - Redirect, Routing, and Authentication
3:32:29 - Code Walkthrough - Routing and Redirect
3:37:35 - POST / Refresh / Redirect
3:48:06 - Code Walkthrough - POST / Redirect
3:54:52 - Implementing Login and Logout
4:05:07 - Code Walkthrough - Login and Logout (3)
4:11:27 - Bonus: Office Hours/Reunion Bletchley Park

WEEK 5 - Building a CRUD Application
Now we build our first 'complete' application that has multiple screens to Create, Read, Update and Delete (CRUD) our data. This brings all the previous concepts together and will form the basis for all later web applications.
4:20:58 - Create, Read, Update and Delete (CRUD)
4:40:59 - Code Walkthrough - CRUD in PHP
4:55:20 - Bonus: Office Hours - Atlanta, Georgia
4:58:36 - Fun: Dr. Chuck Pretends to be a News Anchor
5:02:43 - Fun: Graduation Ceremony

SEE YOU IN THE COURSE 4 - JavaScript, jQuery, and JSON -  THANK'S FOR WATCHING

Don't forget to subscribe and like that helps me keep uploading videos

Thank's For Support!

University of Michigan
The mission of the University of Michigan is to serve the people of Michigan and the world through preeminence in creating, communicating, preserving and applying knowledge, art, and academic values, and in developing leaders and citizens who will challenge the present and enrich the future.

About this Specialization
This Specialization is an introduction to building web applications for anybody who already has a basic understanding of responsive web design with JavaScript, HTML, and CSS. Web Applications for Everybody is your introduction to web application development. You will develop web and database applications in PHP, using SQL for database creation, as well as functionality in JavaScript, jQuery, and JSON.

Over the course of this Specialization, you will create several web apps to add to your developer portfolio. This Specialization (and its prerequisites) will prepare you, even if you have little to no experience in programming or technology, for entry level web developer jobs in PHP.

You’ll demonstrate basic concepts, like database design, while working on assignments that require the development of increasing challenging web apps. From installing a text editor to understanding how a web browser interacts with a web server to handling events with JQuery, you’ll gain a complete introductory overview of web application development.

About this Course
In this course, we'll look at the object oriented patterns available in PHP. You'll learn how to connect to a MySQL using the Portable Data Objects (PDO) library and issue SQL commands in the the PHP language. We'll also look at how PHP uses cookies and manages session data. You'll learn how PHP avoids double posting data, how flash messages are implemented, and how to use a session to log in users in web applications. We'll then build the first 'complete' application that has multiple screens to Create, Read, Update and Delete (CRUD) our data. This brings all the previous concepts together and will form the basis for all later web applications.  It is assumed that learners have already taken the Building Web Applications course in this specialization.

WEEK 1 - PHP Objects

We look at the object oriented patterns available in PHP.

RESOURCES
"The Missing Link" Textbook: Chapters 33

Slides & Embedded Links

Object Oriented Libraries in PHP
http://php.net/manual/en/language.oop5.magic.php

Object Inheritance in PHP
https://www.wa4e.com/code/objects/goodbye.php
https://www.wa4e.com/code/objects/scratch.php
https://www.wa4e.com/code/objects/visibility.php
http://www.php.net/manual/en/language.oop5.visibility.php

Textbook
This course uses an open and free textbook titled, "The Missing Link: An Introduction to Web Development and Programming".

https://milneopentextbooks.org/the-missing-link-an-introduction-to-web-development-and-programming/

Installation Handouts
Setting up your PHP/MySql Development Environment

In this page, you will install a programmer text editor, install a bundled all-in-one PHP/MySql application, and explore that application briefly.

We have separate pages for each of the commonly used Operating Systems:
You can use any software you like - I've done most of my demos using MAMP on the Macintosh so using MAMP might be easier on Windows. If you encounter a problem getting MAMP to work on Windows, it is OK to use XAMPP.

Installing LAMP On Linux
We don't have a video about how to install the software on Linux since there are many different Linux systems and most Linux users already know how to install software. In the Linux world, what we call "MAMP" or "XAMPP" is called "LAMP". Actually LAMP came first and the XAMPP / MAMP names are homage to the original Linux / LAMP.

A simple approach is to search for "How to install LAMP on Ubuntu" - put your variant of Linux in the search - You should find lots of pages. If we find good guides, we will list them here:

Ask Ubuntu: How to set up a LAMP stack

Submitting your code to the autograder
Some of the auto graders in this course will need to contact your application to test it over the Internet. Since your computer normally has a firewall to block incoming connections from the Internet (a very good thing), we need a special program to temporarily "make a tunnel" through your firewall so the auto grader can contact the Apache server running on your local computer.

You can use NGrok to make this tunnel through your firewall. We provide documentation on how to use this application below as well as video walkthroughs both on YouTube and Coursera.
If you have the more advanced skills to put your applications up on the Internet with a real domain name, you do not need to use a tunnel program.

WEEK 2 - Connecting PHP and MySQL

We look at how we connect to a MySQL using the Portable Data Objects (PDO) library and issue SQL commands in the the PHP language.

RESOURCES
Sample Code
http://www.wa4e.com/code/pdo.zip
http://www.wa4e.com/code/rps.zip (Course 1 Web Apps & PHP Week 8 login.php)

Slides & Embedded Links
Windows log file tail utility
http://ophilipp.free.fr/op_tail.htm

Assignment Specification: Autos Database
In this next assignment you will build a web based application to track data about automobiles and store the data in a MySQL database. Note that there is no specific sample code for this assignment.

Sample solution
You can explore a sample solution for this problem at http://www.wa4e.com/solutions/autosdb/
Resources

There are several resources you might find useful:
General Specifications
Here are some general specifications for this assignment:
  • You must use the PHP PDO database layer for this assignment. If you use the "mysql_" library routines or "mysqli" routines to access the database, you will receive a zero on this assignment.
  • Your name must be in the title tag of the HTML for all of the pages for this assignment.
  • Your program must be resistant to HTML Injection attempts. All data that comes from the users must be properly escaped using the htmlentities() function in PHP. You do not need to escape text that is generated by your program.
  • Your program must be resistant to SQL Injection attempts. This means that you should never concatenate user provided data with SQL to produce a query. You should always use a PDO prepared statement.
  • Please do not use HTML5 in-browser data validation (i.e. type="number") for the fields in this assignment as we want to make sure you can properly do server side data validation. And in general, even when you do client-side data validation, you should still validate data on the server in case the user is using a non-HTML5 browser.
Databases and Tables Required for the Assignment
You already should have a PHP hosting environment such as MAMP or XAMPP installed or have some other access to a MySQL client to run commands.

You will need to create a database, a user to connect to the database and a password for that user using commands similar to the following:

create database misc;
GRANT ALL ON misc.* TO 'fred'@'localhost' IDENTIFIED BY 'zap';
GRANT ALL ON misc.* TO 'fred'@'127.0.0.1' IDENTIFIED BY 'zap';

You will need to make a connection to that database in a file like this if you are using MAMP (Macintosh):

<?php
$pdo = new PDO('mysql:host=localhost;port=8889;dbname=misc''fred''zap');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

If you are using XAMPP or Linux your file should change the port to 3306:

<?php
$pdo = new PDO('mysql:host=localhost;port=3306;dbname=misc''fred''zap');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

Usually this file is named pdo.php and is included in each of the files that want to use the database. You will need to change the user name and password on both your GRANT statements and in the code that makes the PDO connection.

You will also need to create and configure a table in the new "misc" database using the following SQL commands:

CREATE TABLE autos (
auto_id INT UNSIGNED NOT NULL AUTO_INCREMENT KEY,
make VARCHAR(128),
year INTEGER,
mileage INTEGER
);

Specifications
The changes to index.php are new wording and pointing to autos.php to test for login bypass.
 
Specifications for the Login Screen
Much of the login.php is reused and extended from the previous assignment [Course 1 Week 8 - Building Web Applications in PHP, Rock Paper Scissors]. The salt and hash computation and most of the error checking comes across unchanged. The password continues to be 'php123'.

The login screen needs to have some error checking on its input data. If either the name or the password field is blank, you should display a message of the form:

Email and password are required

Note that we are using "email" and not "user name" to log in in this assignment.

If the password is non-blank and incorrect, you should put up a message of the form:

Incorrect password

For this assignment, you must add one new validation to make sure that the login name contains an at-sign (@) and issue an error in that case:

Email must have an at-sign (@)

If the incoming password, properly hashed matches the stored stored_hash value, the user's browser is redirected to the autos.php page with the user's name as a GET parameter using:

header("Location: autos.php?name=".urlencode($_POST['who']));

You must also use the error_log() function to issue the following message when the user fails login due to a bad password showing the computed hash of the password plus the salt:

error_log("Login fail ".$_POST['who']." $check");

When the login succeeds (i.e. the hash matches) issue the following log message:

error_log("Login success ".$_POST['who']);

Make sure to find your error log and find those error messages as they come out:

[11-Feb-2016 15:52:03 Europe/Berlin] Login success csev@autos.com

[11-Feb-2016 15:52:13 Europe/Berlin] Login fail csev@autos.com 047398bd0e0171f4954760f5f542121a

Specifications for the Auto Database Screen
In order to protect the database from being modified without the user properly logging in, the autos.php must first check the $_GET variable to see if the user's name is set and if the user's name is not present, the autos.php must stop immediately using the PHP die() function:

die("Name parameter missing");

To test, navigate to autos.php manually without logging in - it should fail with "Name parameter missing".

If the user is logged in, they should be presented with a screen that allows them to append a new make, mileage and year for an automobile. The list of all automobiles entered will be shown below the form. If there are no automobiles in the database, none need be shown.

If the Logout button is pressed the user should be redirected back to the index.php page using:

header('Location: index.php');

When the "Add" button is pressed, you need to do some input validation.

The mileage and year need to be integers. If is suggested that you use the PHP function is_numeric() to determine if the $_POST data is numeric. If either field is not nummeric, you must put up the following message:

Mileage and year must be numeric

Also if the make is empty (i.e. it has less than 1 character in the string) you need to put out a message as follows:

Make is required

Note that only one of the error messages need to come out regardless of how many errors the user makes in their input data. Once you detect one error in the input data, you can stop checking for further errors.

If the user has pressed the "Add" button and the data passes validation, you can add the automobile to the database using an INSERT statement.

 
$stmt = $pdo->prepare('INSERT INTO autos
  (make, year, mileage) VALUES ( :mk, :yr, :mi)');
$stmt->execute(array(
  ':mk' => $_POST['make'],
  ':yr' => $_POST['year'],
  ':mi' => $_POST['mileage'])
);


When you successfully add data to your database, you need to put out a green "success message:

Record inserted

Once there are records in the database they should be shown below the form to add a new entry.

Optional Challenges
This section is entirely optional and is here in case you want to explore a bit more deeply and test your code skillz.

Here are some possible improvements:
  • Always show the automobiles sorted by make regardless of the order they were entered into the application. Hint: use "ORDER BY".
  • Add an optional URL field to your tables and user interface. Validate the URL to make sure it starts with "http://" or "https://". If the user enters a URL, in the list of autos, have the make be a clickable anchor tag that opens the image in a new window:
<a href="http://....jpg" >Ford</a>
  • Medium Difficulty: Use the PHP cURL library to do a GET to the image URL from within PHP and if the URL does not exist, issue an error message to the user and do not add the automobile.
Sample Database Screen Shots
The data in your screen shot(s) should not be the same as these examples.


Autograder: Autos Database
In this assignment you will build a web based application to track data about automobiles and store the data in a MySQL database.

Assignment: https://www.wa4e.com/assn/autosdb/
Solution: https://www.wa4e.com/solutions/autosdb/

Peer graded: Autos Database
In this assignment you will build a web based application to track data about automobiles and store the data in a MySQL database.

Assignment: https://www.wa4e.com/assn/autosdb/
Solution: https://www.wa4e.com/solutions/autosdb/

WEEK 3 - PHP Cookies and Sessions

We look at how PHP uses cookies and manages session data.

RESOURCES
"The Missing Link" Textbook: Chapters 27

Auto-Grader: Cookies and Session
In this assignment we learn about viewing cookies in our browser.

Sample Code: https://www.wa4e.com/code/sessions.zip

WEEK 4 - PHP Redirect, Routing, and Authentication

We look at how PHP avoids double posting data, how flash messages are implemented, and how we use a session to log in users in web applications.

RESOURCES
"The Missing Link" Textbook: Chapters 27

Slides & Embedded Links
PDF Redirect, Routing, and Authentication

Cookies
http://www.wa4e.com/code/sessions/cookie.php

Wiki - Post/Redirect/Get
https://en.wikipedia.org/wiki/Post/Redirect/Get

Mozilla Developer Network - Sending form data
Where does the data go, and how do we handle it when it gets there?

https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Sending_and_retrieving_form_data

Assignment Specification: Autos with Post-Redirect
In this next assignment, you will expand a web based application to track data about automobiles and store the data in a MySQL database. All interactions will follow the POST-Redirect pattern where appropriate. This assignment will interact with 3 PHP files, index.php, autos.php, and view.php (note that view.php is new to this assignment and links out to additional scripts). Note that there is no specific sample code for this assignment.

Sample solution
You can explore a sample solution for this problem at http://www.wa4e.com/solutions/autosess/

Resources
There are several resources you might find useful:
General Specifications

Here are some general specifications for this assignment:

You must use the PHP PDO database layer for this assignment. If you use the "mysql_" library routines or "mysqli" routines to access the database, you will receive a zero on this assignment.

Your name must be in the title tag of the HTML for all of the pages for this assignment.

Your program must be resistant to HTML Injection attempts. All data that comes from the users must be properly escaped using the htmlentities() function in PHP. You do not need to escape text that is generated by your program.

Your program must be resistant to SQL Injection attempts. This means that you should never concatenate user provided data with SQL to produce a query. You should always use a PDO prepared statement.

Please do not use HTML5 in-browser data validation (i.e. type="number") for the fields in this assignment as we want to make sure you can properly do server side data validation. And in general, even when you do client-side data validation, you should still validate data on the server in case the user is using a non-HTML5 browser.

Databases and Tables Required for the Assignment
This assignment reuses the tables from the previous assignment. No additional tables are necessary.

Specifications
The changes to index.php are new wording and pointing to view.php to test for login bypass.

The basic functionality, password checking using salt and hashing, error logging, and data validation for the login.php is the same as in the previous assignment.

There are several changes that are needed for this assignment as follows:
  • The script must redirect after every POST. It must never produce HTML output as a result of a POST operation.
It must redirect to view.php instead of autos.php and must pass the logged in user's name through the session. A GET parameter is not allowed.

<?php // line added to turn on color syntax highlight

// Redirect the browser to view.php
$_SESSION['name'] = $_POST['email'];
header("Location: view.php");
return;

All error messages must be passed between the POST and GET using the session and "flash message" pattern:

<?php // line added to turn on color syntax highlight

$_SESSION['error'] = "Email must have an at-sign (@)";
header("Location: login.php");
return;

The error message must be displayed only on the next GET request.

<?php // line added to turn on color syntax highlight

if ( isset($_SESSION['error']) ) {
  echo('<p style="color: red;">'.htmlentities($_SESSION['error'])."</p>\n");
  unset($_SESSION['error']);
}

Subsequent GET requests (i.e. refreshing the page) should not show the error message to properly implement the POST-Redirect-GET-Flash pattern.
 
Specifications for the Auto Database Screens

The autos.php script from the previous assignment is broken into two scripts in this assignment. The view.php script shows the list of automobiles in the database and the add.php script handles adding new automobiles to the database but does not list any autos. The view.php includes a link to add.php and logout.php and the add.php has a Cancel button.

In order to protect the database from being modified without the user properly logging in, the view.php and add.php must first check the session to see if the user's name is set and if the user's name is not present, the view.php must stop immediately using the PHP die() function:

<?php // line added to turn on color syntax highlight

if ( ! isset($_SESSION['name']) ) {
  die('Not logged in');
}

To test, navigate to view.php manually without logging in - it should fail with "Not logged in".

In view.php if the Logout button is pressed the user should be redirected back to the logout.php page. The logout.php page should clear the session and immediately reditect back to index.php:

<?php // line added to turn on color syntax highlight

session_start();
session_destroy();
header('Location: index.php');

In the add.php script, when the "Add" button is pressed, you need to do the same input validation as in the previous assignment, except that you must display the error using a proper POST-Redirect-GET-Flash pattern.

In the add.php script, when you successfully add data to your database, you need to redirect back to view.php and pass a "success message" to view.php using the session:

<?php // line added to turn on color syntax highlight

$_SESSION['success'] = "Record inserted";
header("Location: view.php");
return;

The view.php must detect and display the success message using the flash pattern:

<?php // line added to turn on color syntax highlight

if ( isset($_SESSION['success']) ) {
  echo('<p style="color: green;">'.htmlentities($_SESSION['success'])."</p>\n");
  unset($_SESSION['success']);
}

What To Hand In
For this assignment you will hand in:
  • A screen shot (including the URL) of your login.php rejecting an account without an at-sign (@). You must also include the developer console network tab showing both the POST and GET.
  • A screen shot of your error log showing correct messages for both a successful and failed login attempt.
  • A screen shot (with URL) of your add.php showing a data validation error. You must also include the developer console network tab showing both the POST and GET.
  • A screen shot (including the URL) of your view.php with three vehicles in the list. At least one of the vehicles must have '<b>' in its title and it must be shown properly (i.e. the title should not be bold)
Grading
Don't take off points for little mistakes. If they seem to have done the assignment give them full credit. Feel free to make suggestions if there are small mistakes. Please keep your comments positive and useful. If you do not take grading seriously, the instructors may delete your response and you will lose points. You need to grade a minimum of 2 peer assignments. You can grade up to 5 peer assignments if you like.

Sample Screen Shots
Some of the screenshots ask to see the developer console demonstrating the POST-Redirect pattern similar to the following:


Some browsers don't actually show two separate requests for the post-redirect. Instead they show the POST and Redirect on the same line. They might produce a screen like the following:


Auto-Grader: Autos with Post-Redirect
In this assignment you will expand a web based application to track data about automobiles and store the data in a MySQL database. All interactions will follow the POST-Redirect pattern where appropriate.

Assignment: https://www.wa4e.com/assn/autosess/
Solution: https://www.wa4e.com/solutions/autosess/

Peer-Grader: Autos with Post-Redirect
In this assignment you will expand a web based application to track data about automobiles and store the data in a MySQL database. All interactions will follow the POST-Redirect pattern where appropriate.

Assignment: https://www.wa4e.com/assn/autosess/
Solution: https://www.wa4e.com/solutions/autosess/


WEEK 5 - Building a CRUD Application

Now we build our first 'complete' application that has multiple screens to Create, Read, Update and Delete (CRUD) our data. This brings all the previous concepts together and will form the basis for all later web applications.

RESOURCES
Sample Code
https://www.wa4e.com/code/crud.zip

Slides & Embedded Links
PDF C.R.U.D

Assignment Specification: Autos C.R.U.D.
In this assignment you will build a web based application to track data about automobiles.

Sample Code
The sample code from the CRUD lecture is a simple working CRUD application: http://www.wa4e.com/code/crud.zip

General Specifications
Here are some general specifications for this assignment:
  • Your name must be in the title tag of the HTML for all of the pages for this assignment.
  • All data that comes from the users must be properly escaped using the htmlentities() function in PHP. You do not need to escape text that is generated by your program.
  • You must follow the POST-Redirect-GET pattern for all POST requests. This means when your program receives and processes a POST request, it must not generate any HTML as the HTTP response to that request. It must use the "header('Location: ...');" function and "return" to send the location header and redirect the browser to the same or a different page.
  • Please do not use HTML5 in-browser data validation (i.e. type="number") for the fields in this assignment as we want to make sure you can properly do server side data validation. And in general, even when you do client-side data validation, you should still validate data on the server in case the user is using a non-HTML5 browser.
Sample Implementation
You can experiment with a reference implementation at: http://www.wa4e.com/solutions/autoscrud

Using the Autograder
This assignment will be automatically graded and so your web server will need an Internet-accessible URL so you can submit it for autograding. To achieve this you will need to install and use a piece of software called "ngrok". Instructions for installing and using ngrok are available at: http://www.wa4e.com/ngrok.php

Please see the process for handing in the assignment at the end of this document.

Important: The autograder will demand that your name is in the <title> tag in the head of your document. If the autograder does not find your name, it will run all the tests but will not treat the grade as official.

Creating Automobile table
You can reuse or adapt a table from a previous assignment. This assignment will need a table as follows:

CREATE TABLE autos (
  autos_id INTEGER NOT NULL KEY AUTO_INCREMENT,
  make VARCHAR(255),
  model VARCHAR(255),
  year INTEGER,
  mileage INTEGER
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


Protecting the add.php and edit.php
In order to protect the database from being modified without the user properly logging in, the add.php and edit.php must first check the session to see if the user's name is set and if the user's name is not set in the session the they must stop immediately using the PHP die() function:

die("ACCESS DENIED");

To test, navigate to add.php manually without logging in - it should fail with "ACCESS DENIED".

Log in
If the user is not logged in, they will be presented a screen with a welcome and a link to login.php - they should not see the table of data.


The autograder will log in to your program with the following account and password:

Account: umsi@umich.edu

Password: php123

The login screen needs to have some error checking on its input data. If either the name or the password field is blank, you should display a message of the form:

User name and password are required

If the password is non-blank and incorrect, you should put up a message of the form:

Incorrect password

Note: Please name your form fields in login.php exactly as follows for autograding:

User Name <input type="text" name="email"><br/>
Password <input type="text" name="pass"><br/>

Automobile Database Main List
Once the user is logged in, they should should be redirected to index.php where they will be shown see a list of the automobiles in the database in a table similar to the following:


If there are no rows in the table, do not print out the table, but simply print out "No rows found".

There should also be options to Add a New Entry and Log Out presented after the table.

If the Logout link is pressed the user should be sent to the logout.php page which clears session variables and redirects back to index.php.

Adding New Records
When the user asks to add a new record, they should be presented with a screen that allows them to append a new automobile. Each automobile will have the following fields:
  • Make
  • Model
  • Year - must be an integer - use is_numeric() to validate
  • Mileage - must be an integer - use is_numeric() to validate
Important: Make sure to name the fields in your forms using the lower case version of the field names so that the autograder can work:

  <input type="text" name="make">

When processing an incoming POST, data must be validated. All fields are required, if there is a missing (i.e. blank) field, issue a message like:

All fields are required

If the user enters a non-numeric field, you should issue a message like:

Year must be an integer

If there are any errors on the input, do not add the record to the stored data. Redirect the user back to the add.php script and display the error message "flash style".

if ( ... at least one of the fields is empty ... ) {
  $_SESSION['error'] = "All fields are required";
  header("Location: add.php");
  return;
}

...

if ( isset($_SESSION['error']) ) {
  echo('<p style="color: red;">'.htmlentities($_SESSION['error'])."</p>\n");
  unset($_SESSION['error']);
}

Note that only one of the error messages need to come out regardless of how many errors the user makes in their input data. Once you detect one error in the input data, you can stop checking for further errors.

If the data validates and the add is successful, redirect to index.php with a successful flash message:

Record added

Editing Records and Validation Errors
When you edit a record, the prior data must be shown and properly escaped. All of the data validation must be performed on the edit data as required in the add.php. Make sure to include the "id" parameter (you may name this variable differently) on the redirect statement in the edit.php when an error is detected:

if ( ... a field is missing ... ) {
  $_SESSION['error'] = "All fields are required";
  header("Location: edit.php?autos_id=".$_REQUEST['id']);
  return;
}

If the data validates and the edit is successful, redirect to index.php with a successful flash message:

Record edited

Deleting Records
When the user selects the "Delete" link from the list of Automobiles you should put up a form with "Delete" and "Cancel" options.

If the "Delete" button is pressed, the record is deleted and the user is redirected to index.php with a success message:

Record deleted

Auto-Grader: Autos CRUD
In this assignment you will expand a web based application to Create, Read, Update, and Delete (C.R.U.D.) data in a MySQL database. All interactions will follow the POST-Redirect and Flash Message patterns where appropriate. All generated HTML must be properly protected using htmlentities().

Assignment: https://www.wa4e.com/assn/autoscrud
Solution: https://www.wa4e.com/solutions/autoscrud

Peer-Grader: Autos CRUD
In this assignment you will expand a web based application to Create, Read, Update, and Delete (C.R.U.D.) data in a MySQL database. All interactions will follow the POST-Redirect and Flash Message patterns where appropriate. All generated HTML must be properly protected using htmlentities().

Assignment: https://www.wa4e.com/assn/autoscrud
Solution: https://www.wa4e.com/solutions/autoscrud


 Thank's for Reading!

No hay comentarios:

Publicar un comentario

Foundations: Data, Data, Everywhere

Google Data Analytics Professional Certificate COURSE 1: Foundations: Data, Data, Everywhere Certified course payment here About this Course...