building an online bidding application using php/mysql

72
Widhy Hayuhardhika NP, S.Kom Building an online bidding application using PHP/MySQL

Upload: norris

Post on 23-Feb-2016

52 views

Category:

Documents


2 download

DESCRIPTION

Building an online bidding application using PHP/MySQL. Widhy Hayuhardhika NP, S.Kom. Outline Topic # 1 MySQL Connection. MySQL Database Connection. Overview of database structure Connecting to MySQL database Selecting the database to use Using the require_once statement. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Building an online bidding application using PHP/MySQL

Widhy Hayuhardhika NP, S.Kom

Building an online bidding application using

PHP/MySQL

Page 2: Building an online bidding application using PHP/MySQL

Outline Topic #1 MySQL Connection

Page 3: Building an online bidding application using PHP/MySQL

Overview of database structureConnecting to MySQL databaseSelecting the database to useUsing the require_once statement

MySQL Database Connection

Page 4: Building an online bidding application using PHP/MySQL

Database: auctionTables

tblaccounttblbiditemstblbidhistory

Overview of Database connection

Page 5: Building an online bidding application using PHP/MySQL

This will hold the account info of bidders/ auctioneers

Table structureColumn accountid: integer, primary key, auto-

incrementColumn username: string 50 charsColumn password: string 50 chars

Table tblaccount

Page 6: Building an online bidding application using PHP/MySQL

This will hold the items auctioned for biddingTable structure

Column biditemid: integer , primary key, auto-increment

Column accountid: string 50 charsThis identifies the auctioneer

Column biditem: string 50 charsColumn biddesc: tiny text

Table tblbiditems

Page 7: Building an online bidding application using PHP/MySQL

This will hold the bid info for each item being auctioned

Table structureColumn bidhistoryid: integer , primary key,

auto-incrementColumn accountid: integerColumn biditemid: integerColumn bidprice: doubleColumn dtesubmitted: datetime

Table tblbidhistory

Page 8: Building an online bidding application using PHP/MySQL

Function mysql_connect:Creates a connection to MySQLSyntax: mysql_connect($hostname, $username,

$password)Ex: $conn=mysql_connect(“localhost”,

“root”,”password”)Function mysql_select_db

Specifies the database in MySQL for useSyntax: mysql_select_db($database,

$connection)Ex: mysql_select_db(“auction”, $conn)

Function dieTerminates execution of PHP script

Connecting to databases:

Page 9: Building an online bidding application using PHP/MySQL

Create file dbconnect.incFor code reuse, a separate file can be created

to connect to the databasePHP pages can call dbconnect.inc to connect

yo the auction database

Connecting to MySQL and selecting auction database

Page 10: Building an online bidding application using PHP/MySQL

Function require_once()Loads a file into a PHP script

Reusing the database connection

Page 11: Building an online bidding application using PHP/MySQL

Outline Topic #2 Creation of Accounts

Page 12: Building an online bidding application using PHP/MySQL

HTML form handlingMySQL commands

Function mysql_query()Function mysql_error()

Adding recordsSQL insert statement

Creation of accounts

Page 13: Building an online bidding application using PHP/MySQL

Create:File index.htmlFile addaccount.htmlFile addaccountprocess.php

$_POST array

HTML form handling

Page 14: Building an online bidding application using PHP/MySQL

First page that displaysProvide the user with the option to create

accounts

File index.html

Page 15: Building an online bidding application using PHP/MySQL

Displays a form for accepting new account info

File addaccount.html

Page 16: Building an online bidding application using PHP/MySQL

$_POST arraySpecial arrays that hold all form variables

Function mysql_query()Executes an SQL statement on the database

Function mysql_error()Displays error encountered when executing an

SQL statementSQL Insert

Adds a record on a database table

File addaccountprocess.php

Page 17: Building an online bidding application using PHP/MySQL

File addaccountprocess.php script

Page 18: Building an online bidding application using PHP/MySQL

Username: auctioneer1This account will place items for bidding

Usernames: bidder1, bidder2These account will bid for item auctioned off

Create accounts:

Page 19: Building an online bidding application using PHP/MySQL

Outline Topic #3 Managing Logins

Page 20: Building an online bidding application using PHP/MySQL

SQL select statementFunction mysql_num_rowsFunction isset()SessionURL rewriting

Querystring $_GET array

Create: File login.php File loginverify.php File checkstatus.inc File menu.php

Managing logins

Page 21: Building an online bidding application using PHP/MySQL

Example 1: select * from tblaccount Selects all columns/ rows from table tblaccount

Example 2: select username, password from tblaccount Selects columns username and password for all rows in

table tblaccountExample 3: select * from tblaccount where

username=‘jundolor’ Selects all columns from table tblaccount for all rows

whose column username contains ‘jundolor’Example 4: select accountid from tblaccount where

username=‘media’ Selects column accountid from tblaccount for all rows

whose column username contains ‘media’

SQL select statement

Page 22: Building an online bidding application using PHP/MySQL

Retrieves the number of rows from a result set

Can only be used for SQL select statements

Function mysql_num_rows

Page 23: Building an online bidding application using PHP/MySQL

Checks if a variable existExample: isset($name)

This check if the variable $name exist

Function isset()

Page 24: Building an online bidding application using PHP/MySQL

Special variables stored in web serversAllows passing of information between web

pagesCall the function session_start() at the start of

scripts that will use sessions

Sessions

Page 25: Building an online bidding application using PHP/MySQL

QuerystringInformation can be passed on by appending

variable/value to the URL

$_GET arraySpecial array that holds all querystring values

URL Rewriting

Page 26: Building an online bidding application using PHP/MySQL

File login.php code

Page 27: Building an online bidding application using PHP/MySQL

File login.php browser shot

Page 28: Building an online bidding application using PHP/MySQL

File loginverify.php code

Page 29: Building an online bidding application using PHP/MySQL

File checkstatus.inc code

Page 30: Building an online bidding application using PHP/MySQL

File menu.php

Page 31: Building an online bidding application using PHP/MySQL

Outline Topic #4 Adding Items to Auction

Page 32: Building an online bidding application using PHP/MySQL

File menu.phpCreate:

File addauctionitem.phpFile addauctionitemprocess.php

Adding items to auction

Page 33: Building an online bidding application using PHP/MySQL

File menu.php

Page 34: Building an online bidding application using PHP/MySQL

File addauctionitem.php code

Page 35: Building an online bidding application using PHP/MySQL

File addauctionitem.php screen shot

Page 36: Building an online bidding application using PHP/MySQL

File addauctionprocess.php

Page 37: Building an online bidding application using PHP/MySQL

Outline Topic #5 Deleting Bid Items

Page 38: Building an online bidding application using PHP/MySQL

Function mysql_fetch_array()Writing querystring URL to identify records

to deleteSQL delete statementCreate:

File listauctionitems.phpFile: deletebiditem.php

Deleting Bid Items

Page 39: Building an online bidding application using PHP/MySQL

Fetches a row as an associative from a select query result set

Function mysql_fetch_array()

Page 40: Building an online bidding application using PHP/MySQL

Sample mysql_fetch_array() code

Page 41: Building an online bidding application using PHP/MySQL

Auction items belonging to current account will be selected

A loop will be created to go through each rowEach row will hyperlink to a PHP based page

for deletionTo identify the row, a querystring variable will

be appended to the URL

Writing querystring URLto identify records to delete

Page 42: Building an online bidding application using PHP/MySQL

Writing querystring URLto identify records to delete- code

Page 43: Building an online bidding application using PHP/MySQL

Example 1: delete from tblaccountDeletes all rows on table tblaccount

Example 2: delete from tblaccount where accountid=1Deletes only rows matching the condition

SQL delete statement

Page 44: Building an online bidding application using PHP/MySQL

File menu.php

Page 45: Building an online bidding application using PHP/MySQL

File listauctionitems.php

Page 46: Building an online bidding application using PHP/MySQL

File deletebiditem.php

Page 47: Building an online bidding application using PHP/MySQL

Outline Topic #6 Logging Out

Page 48: Building an online bidding application using PHP/MySQL

Function session_destroy()Create:

File logout.php

Loggin out

Page 49: Building an online bidding application using PHP/MySQL

Terminates all session variables stored in server memory

Function session_destroy()

Page 50: Building an online bidding application using PHP/MySQL

File menu.php

Page 51: Building an online bidding application using PHP/MySQL

Once logout.php is called, all session variable will be dropped from server memory

Browser will not be able to access any page calling checkverify.php (ex: menu.php)

File logout.php

Page 52: Building an online bidding application using PHP/MySQL

Outline Topic #7 Viewing Bid Items

Page 53: Building an online bidding application using PHP/MySQL

Establishing relations between tablesSQL natural join clauseCreate:

File listbiditems.php

Viewing bid items

Page 54: Building an online bidding application using PHP/MySQL

Establishing relationsTable tblbiditem

Holds the items being auctioned off

Column accountid identifies the owner if the auctioned item

Table tblaccount Holds account

information of the owner of the item being auctioned

Column accountid Links the owner of the

account to the auction item

Page 55: Building an online bidding application using PHP/MySQL

Used with SQL select statementConnects rows between different tables via

their common column

SQL natural join clause

Page 56: Building an online bidding application using PHP/MySQL

File menu.php

Page 57: Building an online bidding application using PHP/MySQL

All items with their respective owners being auction are listed

Each item will hyperlink to a PHP page for accepting bidsAccepting bids will be covered in the next topic

sectionEach hyperlink will append a querystring

variable to identify it in the PHP page for accepting bids

File listbiditems.php

Page 58: Building an online bidding application using PHP/MySQL

File listbiditems.php code

Page 59: Building an online bidding application using PHP/MySQL

File listbiditems.php screen shot

Page 60: Building an online bidding application using PHP/MySQL

Outline Topic #7 Accepting Bids

Page 61: Building an online bidding application using PHP/MySQL

Using hidden fields to store ID numbersMySQL now() functionCreate:

File acceptbid.phpFile acceptbidprocess.php

Accepting bids

Page 62: Building an online bidding application using PHP/MySQL

Not displayed to the browserUsed to pass constant values

Hidden fields

Page 63: Building an online bidding application using PHP/MySQL

Place the id of the auction item in a hidden fieldFile acceptbid.php

Page 64: Building an online bidding application using PHP/MySQL

File acceptbid.php screen shot

Page 65: Building an online bidding application using PHP/MySQL

File acceptbid.php HTML generated code

Page 66: Building an online bidding application using PHP/MySQL

Returns the current date and time as a value in 'YYYY-MM-DD HH:MM:SS' or YYYYMMDDHHMMSS.uuuuuu formatdepending on whether the function is used in a

string or numeric contextThe value is expressed in the current time

zone.

MySQL now() function

Page 67: Building an online bidding application using PHP/MySQL

File acceptbidprocess.php

Page 68: Building an online bidding application using PHP/MySQL

Resulting records

Page 69: Building an online bidding application using PHP/MySQL

Outline Topic #9 Listing Bids For Each Bid Item

Page 70: Building an online bidding application using PHP/MySQL

MySQL date_format() functionRelating information from two or more tablesSQL order by clause

Listing bids for each bid item

Page 71: Building an online bidding application using PHP/MySQL

Formats a string based on a specified formatThe following are some of the specifies of the

format string:%D: Day of month with English suffix%d: Numeric day of month (01…31)%M: Month name (January…December)%m: Month numeric (01…12)%Y: Year (4 digits)%y: Year (2 digits)

MySQL date_format() function

Page 72: Building an online bidding application using PHP/MySQL

MySQL date_format() sample