Internet Information Systems Writing to Databases and Amending Data.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Relational Database Systems Higher Information Systems Advanced Implementation in MySQL/PHP.
Keys, Referential Integrity and PHP One to Many on the Web.
1Key – Report Creation with DB2. DB2 Databases Create Domain for DB2 Test Demo.
Web Database Programming Connecting Database to Web.
INTRODUCTION The Group WEB BROWSER FOR RELATION Goals.
Manipulating MySQL Databases with PHP. PHP and mySQL2 Objectives Connect to MySQL from PHP Learn how to handle MySQL errors Execute SQL statements with.
LCT2506 Internet 2 Further SQL Stored Procedures.
Objectives Connect to MySQL from PHP
MySQL and PHP By Trevor Adams.
Tutorial 14 Working with Forms and Regular Expressions.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
Preventing SQL Injection ~example of SQL injection $user = $_POST[‘user’]; $pass = $_POST[‘pass’]; $query = DELETE FROM Users WHERE user = ‘$user’ AND.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
XP Tutorial 14 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Web forms in PHP Forms Recap  Way of allowing user interaction  Allows users to input data that can then be processed by a program / stored in a back-end.
Chapter 4 Handling User Input PHP Programming with MySQL 2nd Edition
JavaScript Form Validation
1 Chapter 6 – Creating Web Forms and Validating User Input spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information.
PHP1-1 PHP & SQL Xingquan (Hill) Zhu
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
Server-Side Validation Jayden Bryant. What is Server-Side Validation?  Validation of form input done on the server, not the web browser program //Validate.
Tutorial 14 Working with Forms and Regular Expressions.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Creating databases for web applications Play quizzes Testing process regular expressions: form validation PHP coding handling forms Homework: regular expressions.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
COP 3813 Intro to Internet Computing Prof. Roy Levow PHP.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
Lesson 2.  To help ensure accurate data, rules that check entries against specified values can be applied to a field. A validation rule is applied to.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
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.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Lec_6 Manipulating MySQL Databases with PHP PHP Programming with MySQL.
MySQL Databases & PHP Integration Using PHP to write data to, and retrieve data from, a MySQL database.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
1. Connecting database from PHP 2. Sending query 3. Fetching data 4. Persistent connections 5. Best practices.
NMD202 Web Scripting Week3. What we will cover today Includes Exercises PHP Forms Exercises Server side validation Exercises.
System Initialization 1)User starts application. 2)Client loads settings. 3)Client loads contact address book. 4)Client displays contact list. 5)Client.
Database Access with PHP and MySQL CS356 Examples from Web Database Applications, by Hugh E. Williams & David Lane, O'Reilly, 2002.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Web-Based Database Programming with PHP. Dept. of Computing Science, University of Aberdeen2 In this lecture you will learn PHP Basics PHP functions –To.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
Creating PHPs to Insert, Update, and Delete Data CS 320.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
Security Considerations Steve Perry
>> PHP: Insert Query & Form Processing. Insert Query Step 1: Define Form Variables Step 2: Make DB Connection Step 3: Error Handling Step 4: Define the.
CSCI 6962: Server-side Design and Programming JSF DataTables and Shopping Carts.
WEB SECURITY WEEK 2 Computer Security Group University of Texas at Dallas.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
Windows 7 WampServer 2.1 MySQL PHP 5.3 Script Apache Server User Record or Select Media Upload to Internet Return URL Forward URL Create.
>> PHP: MySQL & CRUD. R ecall Database Tables Records is composed of Operations (CRUD) Create Retrieve Update Delete DBMS Access Control MySQL phpMyAdmin.
CSC 405: Web Application Engineering II8.1 Web programming using PHP What have we learnt? What have we learnt? Underlying technologies of database supported.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
CSCI 6962: Server-side Design and Programming Shopping Carts and Databases.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
Programming for the Web MySQL Command Line Using PHP with MySQL Dónal Mulligan BSc MA
Performance and User Experience Improvements to the ASU/NASA Space Grant Website
ISC440: Web Programming 2 Server-side Scripting PHP 3
Accessing Your MySQL Database from the Web with PHP (Ch 11)
Database Access with PHP and MySQL
Presentation transcript:

Internet Information Systems Writing to Databases and Amending Data

Objectives Review Inserting data Cleaning data Redirects/Receipts Server-side validation Amending and deleting data Issues in writing data

Review Create tables & display data DEMO phpMyAdmin, filmscript Viewfilm.php Querying data -DEMO examples Demo cat_products.php As well as reading data, also need to Insert, Amend and Delete Uses - Shopping carts, personalisation,

Data Insertion – Phases Client: Data collection Web Form + Client-side validation Server: Check Data Submitted & Clean Check data arrived Check for dodgy characters. Data Validation Data is in correct format for entry into database. Insert/Amend the data

Data Submitted Demo AddAnimal.php <?php $country = $_GET['country']; $animal = $_GET['animal']; // If no user input, then present Form if (empty($animal) || empty($country)) { //Error – go back to form} Could use empty function if (empty($animal) || empty($country)) Demo Create User isset function to see if form is submitted

Cleaning Data Avoid bad characters = ‘ “” \ nulls Magic quotes - all escaped with a backslash automatically Set on server mysql_real_escape_string($somestring); Clean white space at beginning or end. Trim $newuser = trim($newuser);

Reloading Data Problem http is ‘Stateless’ => ‘reload’ problem with inserts/updates. Submit details – then Refresh Variables & values are resubmitted Can avoid with redirection -> receipt? http Location:header CreateUserWithReceipt if (record added) header("Location: userReceipt.php?status=T“); else header("Location: userReceipt.php? status=F“)

Server-Side Validation Must ensure data is in correct format for database – validation by: Database or Server-Side scripts Database Could php mysql_error() function to trap errors returned from DB Server-Side Scripts Submit form – then check fields Can use regular expressions int ereg ( string pattern, string string [, array &regs] )

Regular Expressions PHP Functions ereg() and eregi() int ereg ( string pattern, string string [, array &regs] ) $String = “Course Technology” ereg(“course technology”, $String) //returns false ereg(“Course Technology”, $String) //returns false eregi(“course technology”, $String) //returns false You can see these functions would be useful in searches ^ means start of a string $ means the end of a string [0-9] means there must be a digit from 0 – 9 {4} means there must be 4 in quantity Demo – CustomerDetailsError.php ereg("^([0-9]{2})/([0-9]{2})/([0-9]{4})$", $dob, $parts))

Database Updates and Deletes Update - usually 3 stages 1. Using key value - matching data is read from the database 2. The data is presented for modification 3. The data is updated using the key value from the first step. Demo - CustUpdateInsert $query = "UPDATE customer SET surname = '$surname', ……

Example - Delete 1. Identify row or rows to be deleted 2. Remove data with SQL DELETE Demo DeleteAnimal – getting ID $query = "DELETE FROM symbols WHERE id = ".$_GET['id']; mysql_affected_rows() Demo Cust_delete

Writing To Databases - Issues Multiple users – simultaneous insertion, deletion and updating Unrepeatable reads (stock, planes) Transactions – viable and complete Concurrency – same row being altered Locking mechanisms provided by mySQL

Summary Reviewed Create tables in MySQL View and Query data Collect, clean, validate data before inserting or amending Validation (searching) using regular expressions Avoid ‘Reload’ problem with redirect Updates and Deletes