pset 7: C$50 Finance Zamyla Chan zamyla@cs50.net



Similar documents
Problem Set 7: C$50 Finance

Web Development using PHP (WD_PHP) Duration 1.5 months

Online shopping store

How To Let A Lecturer Know If Someone Is At A Lecture Or If They Are At A Guesthouse

HowTo. Planning table online

B2C E-COMMERCE WEBSITE

RoboMail Mass Mail Software

Report on the Train Ticketing System

OpenPro ERP Software Installation Guide REDHAT LINUX

CSCI110 Exercise 4: Database - MySQL

Lesson 7 - Website Administration

1: 2: : 3.1: 3.2: 4: 5: & CAPTCHA

shweclassifieds v 3.3 Php Classifieds Script (Joomla Extension) User Manual (Revision 2.0)

HOW TO SELL A STOCK BY KELLY GREEN

Role Based Access Control. Using PHP Sessions

User Manual for efiling of Return for VAT (ver. 2.2) Download/ Upload Return Filing Method E-FILING RETURN FOR

Advanced Tornado TWENTYONE Advanced Tornado Accessing MySQL from Python LAB

NO SQL! NO INJECTION?

Project 2: Web Security Pitfalls

Top Navigation menu - Tabs. User Guide 1. &

Facebook Twitter YouTube Google Plus Website

Salesforce Customer Portal Implementation Guide

How to Create a Custom TracDat Report With the Ad Hoc Reporting Tool

How To Use Webmail. Guiding you through the Universities online

INSTALLING, CONFIGURING, AND DEVELOPING WITH XAMPP

1) After login WinTonenet Securities Trading System, a window named WinTonenet Securities Trading will be shown.

Here is a quick diagram of the ULV SSO/Sync Application. Number 3 is what we deal with in this document.

Gravity Forms: Creating a Form

Contactegration for The Raiser s Edge

Database Security. Principle of Least Privilege. DBMS Security. IT420: Database Management and Organization. Database Security.

Last Updated on 11/06/

CPE111 COMPUTER EXPLORATION

No SQL! no injection? A talk on the state of NoSQL security

Paytelligence Quick Start Guide

Streamlining Purchases with Website Payment Preferences

Add User to Administrators Group using SQL Lookup Table

Tutorial Guide to the IS Unix Service

DIPLOMA IN WEBDEVELOPMENT

ReportBy Notification Examples

HELP DESK MANUAL INSTALLATION GUIDE

Creating a Participants Mailing and/or Contact List:

E-Commerce User Instructions

Once you ve signed up, all you ll have to do is sign in. To sign in key in your address and password.

Alliance istock Mobile Trading. User Guide for Apple iphone & Android Devices

Copyright 2011 Business Management Systems. Web Based ERP/CRM Software

An Introduction to Developing ez Publish Extensions

Network License File. Program CD Workstation

Business Portal for Microsoft Dynamics GP. Key Performance Indicators Release 10.0

How To Set Up Total Recall Web On A Microsoft Memorybook (For A Microtron)

CEFNS Web Hosting a Guide for CS212

Selling Digital Goods Online

Online Multimedia Winter semester 2015/16

CS 145: NoSQL Activity Stanford University, Fall 2015 A Quick Introdution to Redis

Version USER GUIDE

Personal Portfolios on Blackboard

UQC103S1 UFCE Systems Development. uqc103s/ufce PHP-mySQL 1

Content Management System

IIS SECURE ACCESS FILTER 1.3

Accounts Receivable WalkThrough

Uni Sales Analysis CRM Extension for Sage Accpac ERP 5.5

ADMINISTRATOR GUIDE VERSION

WEB BASED Access Control/Time Attendance Software Manual V 1.0

USER MANNUAL. Version 1.9.6

introduction to emarketing

Specific Information for installation and use of the database Report Tool used with FTSW100 software.

EU-METALIC II Application Process

Shop Manager Manual ConfigBox 3.0 for Magento

Form And List. SuperUsers. Configuring Moderation & Feedback Management Setti. Troubleshooting: Feedback Doesn't Send

A table is a collection of related data entries and it consists of columns and rows.

Welcome to Collage (Draft v0.1)

Online Payments. Intel Learn Easy Steps Activity Card

Admin Reference Guide. PinPoint Document Management System

Online Systems at COTR. Learn about COTRs Online Systems, how to log into them, activate your accounts and set up your passwords.

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

IBM Rational University. Essentials of IBM Rational RequisitePro v7.0 REQ370 / RR331 October 2006 Student Workbook Part No.

Mastering Mail Merge. 2 Parts to a Mail Merge. Mail Merge Mailings Ribbon. Mailings Create Envelopes or Labels

SAS Visual Analytics 7.1 for SAS Cloud. Quick-Start Guide

Application note: Connecting the to a Database

Accounts Receivable Invoice Upload

October Easy Steps to use ESCIMS At Point of Sale

Basics Series Basics Version 9.0

LogLogic General Database Collector for Microsoft SQL Server Log Configuration Guide

COLLABORATION NAVIGATING CMiC

Site Monitor. Version 5.3

INTRODUCTION... 4 GETTING STARTED... 5

Vector HelpDesk - Administrator s Guide

SelectSurvey.NET Basic Training Class 1

Banner Training Manual: Department Chairs

How to Create a Spreadsheet With Updating Stock Prices Version 3, February 2015

1. To start Installation: To install the reporting tool, copy the entire contents of the zip file to a directory of your choice. Run the exe.

Transcription:

pset 7: C$50 Finance Zamyla Chan zamyla@cs50.net

Toolbox permissions HTML PHP SQL

permissions use chmod in the Terminal to change permissions of files and folders chmod a+x folder folder executable by everyone chmod a+r css/* img/* js/* everything in css, img, js directory readable by everyone

permissions rwx 111 7 rw 110 6 rx 101 5 r 100 4 wx 011 3 w 010 2 x 001 1

permissions folders: chmod 711 folder images, HTML, CSS, js: chmod 644 file users shouldn t execute an image! php files: chmod 600 file users shouldn t see your PHP code!

PHP files end in.php can mix HTML with php code enclosed in <?php?> variables start with $ weakly typed associative arrays! $arr =["a" => 1, "b" => 2, "c" => 3]; $arr["a"] equals 1

C$50 Finance 0. A Section of Questions 1. CS50 Finance 1. register 2. quote 3. portfolio 4. buy 5. sell 6. history 7. extra feature

Setup cd ~/vhosts/localhost unzip pset7.zip chmod the files and directories visit http://localhost/ inside the appliance

Distribution Code html includes templates

includes/functions.php apologize dump logout lookup($symbol) returns a stock symbol query executes SQL statement redirect render outputs a template

register Display form Check passwords: not blank, match Add user to database Log them in

display form copy login.php and login_form.php <form action="register.php" method="post"> send data to register.php instead Need to make a password confirmation field

register Display form Check passwords: not blank, match Add user to database Log them in

valid passwords? make sure $_POST["password"] and $_POST["confirmation"] aren t blank else, apologize make sure $_POST["password"] and $_POST["confirmation"] are the same else, apologize "omg" == "omg" in PHP!! goobye, strcmp!

apologies apologize("passwords do not match!");

register Display form Check passwords: not blank, match Add user to database Log them in

usernames make sure $_POST["username"] isn t blank, else apologize usernames are a UNIQUE field in the database query returns false on failure $result = query( ) if ($result === false) then an error occurred (e.g., duplicate username)

SQL Queries: INSERT INSERT INTO users (username, hash, cash) VALUES ("zamyla", '$1$50$Suq.MOtQj51maavfKvFsW1', 10000.00) inserts a new row into users

query? is a placeholder query("insert INTO users (username, hash, cash) VALUES(?,?, 10000.00)", $_POST["username"], crypt($_post["password"]));

query? is a placeholder query("select * FROM users WHERE username =?", $_POST["username"]);

register Display form Check passwords: not blank, match Add user to database Log them in

logging in once they register successfully, should be logged in automatically Find out their id $rows = query("select LAST_INSERT_ID() AS id"); $id = $rows[0]["id"]; Store their id in session $_SESSION

register Display form Check passwords: not blank, match Add user to database Log them in

quote form for search retrieve stock quote display stock quote

form form in quote.php input: symbol the user wants to look up send data to quote_form.php

quote form for search retrieve stock display stock information

lookup $s = lookup("aapl") returns an associative array symbol name price

quote form for search retrieve stock display stock quote

displaying stock information at minimum, display quote ensure the stock is valid else: apologize, as usual print("price: ". $s["price"]); But, need to format to 2 to 4 decimal places, as with number_format.

quote form for search retrieve stock display stock quote

portfolio portfolio table displaying the portfolio

portfolio table users id username hash cash portfolios id symbol shares

portfolio portfolio table displaying the portfolio

displaying the portfolio report, at minimum: each of the stocks in a user's portfolio number of shares current value (price times number) user's current cash balance

displaying the portfolio index.php is the controller render("portfolio.php",...); portfolio.php is the template what variables does it need?

displaying the portfolio query returns an array of rows $rows = query("select symbol, shares FROM tbl WHERE id =?", $_SESSION["id"]); foreach ($rows as $row) { print("<tr>"); print("<td>{$row["symbol"]}</td>"); print("<td>{$row["shares"]}</td>"); print("</tr>"); }

buying stocks get stock, number of shares add stock to portfolio update cash

form HTML form ask for symbol and number of shares

buying stocks get stock, number of shares add stock to portfolio update cash

SQL Queries: SELECT SELECT * FROM users WHERE username = "skroob" gets the data from every column in the table called users only if the username column has the value skroob

adding shares to portfolio error-checking! can the user afford the stock? SELECT cash FROM users WHERE id = 7 buying the same stock INSERT INTO portfolio (id, symbol, shares) VALUES(7, 'DVN.V', 10) ON DUPLICATE KEY UPDATE shares = shares + VALUES(shares)

buying stocks get stock, number of shares add stock to portfolio update cash

update cash a user s cash is stored in the users table UPDATE users SET cash = cash 9999 WHERE id = 7 price of the stock * number of shares

buying stocks get stock, number of shares add stock to portfolio update cash

selling stocks get stock to sell remove stock from portfolio update cash

selling stocks display the user s stocks SELECT * FROM portfolio WHERE id = 7 delete stock from user s portfolio DELETE FROM portfolio WHERE id = 7 AND symbol = "AAPL" update cash stock is sold at its current price

selling stocks get stock to sell remove stock from portfolio update cash

history keep track of all transactions

history history table every purchase and sale add a row to history store the timestamp of the transaction NOW() CURRENT_TIMESTAMP

index.php must link to, at minimum: buy.php history.php logout.php quote.php sell.php

1 Extra Feature!

1 Extra Feature Password change Password reset registration takes an email address email a link to reset password Email users "receipts" anytime they buy or sell stocks. Add cash

have fun!

this was walkthrough 7

these were psets

these were walkthroughs