Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.

Slides:



Advertisements
Similar presentations
PHP: Date() Function The PHP date() function formats a timestamp to a more readable date and time.
Advertisements

PHP II Interacting with Database Data. The whole idea of a database-driven website is to enable the content of the site to reside in a database, and to.
PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
Web Database Programming Connecting Database to Web.
NMED 3850 A Advanced Online Design February 25, 2010 V. Mahadevan.
Manipulating MySQL Databases with PHP. PHP and mySQL2 Objectives Connect to MySQL from PHP Learn how to handle MySQL errors Execute SQL statements with.
Objectives Connect to MySQL from PHP
Intermediate PHP & MySQL
SJSU CS157B Dr. Lee1  2004 Jenny Mitchell Two Useful Tools You Can’t Live Without by Jenny Mitchell SJSU CS157B Section PHP and MySQL.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
What is MySQL? MySQL is a database. The data in MySQL is stored in database objects called tables. A table is a collections of related data entries and.
PHP1-1 PHP & SQL Xingquan (Hill) Zhu
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
INTERNET APPLICATION DEVELOPMENT For More visit:
MySQL + PHP.  Introduction Before you actually start building your database scripts, you must have a database to place information into and read it from.
PHP MySQL Introduction
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
INTERNET APPLICATION DEVELOPMENT PRACTICAL ON CONNECTING TO MYSQL.
MySQL + PHP.  Introduction Before you actually start building your database scripts, you must have a database to place information into and read it from.
 Mysql – popular open-source database management system  PHP usually works with Mysql for web- based database applications  LAMP applications—Web-based.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
MySQL Databases & PHP Integration Using PHP to write data to, and retrieve data from, a MySQL database.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Creating PHPs to Insert, Update, and Delete Data CS 320.
CIS166AE : PHP Web Scripting Rob Loy. Tonight’s Agenda Housekeeping items Housekeeping items PHP basics PHP basics Student connection to server Student.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Inserting Data.
DT228/3 Web Development Databases. Querying a database: Partial info Search engines, on-line catalogues often need to allow user to search a database.
PHP and Mysql Database. PHP and Database Mysql – popular open-source database management system PHP usually works with Mysql for web-based database applications.
Module Review Basic SQL commands: Create Database, Create Table, Insert and Select 2. Connect an SQL Database to PHP 3. Execute SQL Commands in.
PHP getting data from a MySQL database. Replacing XML as data source with MySQL Previously we obtained the data about the training session from an XML.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
CHAPTER 10 PHP MySQL Database
CSC 2720 Building Web Applications Accessing MySQL from PHP.
MySQL MySQL and PHP – interacting with a database.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Introduction to MySQL Ullman Chapter 4. Introduction MySQL most popular open-source database application Is commonly used with PHP We will learn basics.
به نام خدا SQL QUIZ جوانمرد Website: ejavanmard.blogfa.com.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
Programming for the Web MySQL Command Line Using PHP with MySQL Dónal Mulligan BSc MA
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
Tried my best to simplify it for you!
Web Systems & Technologies
Chapter 5 Introduction to SQL.
CS320 Web and Internet Programming SQL and MySQL
Web Design and Development
Database application MySQL Database and PhpMyAdmin
Introduction to Web programming
ISC440: Web Programming 2 Server-side Scripting PHP 3
Web Systems Development (CSC-215)
PHP: Security issues FdSc Module 109 Server side scripting and
Tutorial 6 PHP & MySQL Li Xu
CS3220 Web and Internet Programming SQL and MySQL
CS3220 Web and Internet Programming SQL and MySQL
Introduction to Web programming
Presentation transcript:

Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy

Agenda Homework/Lab Review Homework/Lab Review Presentations Presentations SQL Update SQL Update Creating SQL Tables Creating SQL Tables Validation Validation Mid-term Project Mid-term Project

Database Infrastructure

IMPORTANT NOTE A Database Server can not have a DB with the same name. Since we use ONE DB Server, all our DBs have to have unique names.

Information needed for DB Need server name/IP (e.g. mysql..com or localhost) Need server name/IP (e.g. mysql..com or localhost) Need username Need username Need password Need password Need DB name Need DB name Need table names Need table names Need column names Need column names

IMPORTANT NOTE SQL Commands (SELECT, INSERT, UPDATE, etc) are almost always written in CAPS and other pieces of a SQL statement are written as normal case.

IMPORTANT NOTE Never do a DELETE statement, instead “archive” the date.

PHP / mySQL Syntax // Connect to server $con = mysql_connect(“SERVER",“USER",“PASSWORD"); // Connect to DB mysql_select_db(“DATABASE", $con); // Execute SQL Query $result = mysql_query("SELECT * FROM TABLE"); // The RECORDSET will be an object (e.g. $result) // Need to break the object into an array (e.g. $row) while($row = mysql_fetch_assoc($result)) { // The WHILE runs until END OF RECORD echo $row['FirstName']. " ". $row['LastName‘]." "; } // Close connection mysql_close($con);

Connecting to your DB Server: mysql..com Server: mysql..com Username: sccstudent_ Username: sccstudent_ Password: Maricopa_ Password: Maricopa_ DB name: sccstudent_ DB name: sccstudent_ Table: week4 Table: week4 Columns: id, username, password, firstname, lastname, phone, , created Columns: id, username, password, firstname, lastname, phone, , created

PHP / SQL Update Steps SELECT statement to pull ONE record SELECT * FROM persons WHERE id = 1; SELECT statement to pull ONE record SELECT * FROM persons WHERE id = 1; Use the result from step one to populate the HTML form fields ” /> Use the result from step one to populate the HTML form fields ” /> After user submits, take value and UPDATE the table UPDATE person SET fname=”$_POST[“first”]” WHERE id=1; After user submits, take value and UPDATE the table UPDATE person SET fname=”$_POST[“first”]” WHERE id=1;

Form Data Validation Client side: Javascript Client side: Javascript Make sure information is filled out BEFORE sending to the server. Make sure information is filled out BEFORE sending to the server. Saves unnecessary traffic. Saves unnecessary traffic. Maintains user entry seamlessly. Maintains user entry seamlessly. Sever side: PHP Sever side: PHP Users can disable Javascript. Users can disable Javascript. Content can be created maliciously access/update the DB. Content can be created maliciously access/update the DB. More control closer to the SQL statement. More control closer to the SQL statement.

Validation Test Is Null or Empty Is Null or Empty Type text vs. numeric Type text vs. numeric Is an address, phone, social security, etc. Is an address, phone, social security, etc. Limited number of characters Limited number of characters HTML code HTML code Special characters Special characters Malicious code (e.g. WHERE 1=1) Malicious code (e.g. WHERE 1=1)

JavaScript Validation function fValid(){ var x=document.forms[“form1"][“first"].value; if (x==null || x=="") { alert("First name must be filled out"); return false; } } function fValid(){ var x=document.forms[“form1"][“first"].value; if (x==null || x=="") { alert("First name must be filled out"); return false; } } First: First:

IMPORTANT NOTE The life cycle in PHP is the length of time it takes the server to find the file, process the information, and send the completed static HTML back to the client.

Sort DB records SELECT * FROM persons ORDER BY fname ASC; SELECT * FROM persons ORDER BY fname ASC; SELECT * FROM persons ORDER BY fname DESC; SELECT * FROM persons ORDER BY fname DESC; The ORDER BY keyword is used to sort the result-set by a specified column. The ORDER BY keyword is used to sort the result-set by a specified column. The ORDER BY keyword sort the records in ascending order by default. The ORDER BY keyword sort the records in ascending order by default. If you want to sort the records in a descending order, you can use the DESC keyword. If you want to sort the records in a descending order, you can use the DESC keyword.

phpMyAdmin

mySQL Data Types Numeric Numeric Float Float Integer Integer String String Char Char Varchar Varchar Date Date

Create a new mySQL Table Log into the phpmyadmin site Log into the phpmyadmin site Select a DB from right column Select a DB from right column Create a table name and pick number of columns Create a table name and pick number of columns

Create mySQL Table Structure Name each field Name each field Select a Type Select a Type Assign a length for VARCHAR or CHAR types Assign a length for VARCHAR or CHAR types Design default values Design default values Determine if NULL values allowed by using NULL checkbox Determine if NULL values allowed by using NULL checkbox Pick one field as ID and select INT type and A_I checkbox Pick one field as ID and select INT type and A_I checkbox

phpmyadmin screen

In class Update SQL DB Update SQL DB Sort SQL Recordsets Sort SQL Recordsets Create Table Create Table

Questions?

Lab Display the “create” field from the table Display the “create” field from the table Update the form to allow the user to modify firstname, lastname, phone, and address Update the form to allow the user to modify firstname, lastname, phone, and address Add sort by lastname (sort for firstname from class should also work) Add sort by lastname (sort for firstname from class should also work) Send to with URL to input form file before 6pm on October 12. Send to with URL to input form file before 6pm on October

Mid-term Project Create mySQL table that has at least 5 fields Create mySQL table that has at least 5 fields One field should be ID with Auto Increment One field should be ID with Auto Increment Display all records from the table Display all records from the table Create a web form that has INSERT and UPDATE functionality for the table Create a web form that has INSERT and UPDATE functionality for the table Add a sort functionality Add a sort functionality At least 2 have to be required and display error messages where appropriate At least 2 have to be required and display error messages where appropriate Send to with URL to input form file before 6pm on October 19. Send to with URL to input form file before 6pm on October