Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.

Slides:



Advertisements
Similar presentations
The Librarian Web Page Carol Wolf CS396X. Create new controller  To create a new controller that can manage more than just books, type ruby script/generate.
Advertisements

Keys, Referential Integrity and PHP One to Many on the Web.
Mark Dixon Page 1 23 – Object Oriented Programming in PhP.
Mark Dixon Page 1 16 – Passing Data between pages: Forms, Sessions, & Query Strings.
Mark Dixon Page 1 05 – Database Design: Sub-forms.
Mark Dixon Page 1 04 – Database Design: Forms. Mark Dixon Page 2 Session Aims & Objectives Aims –To allow easier data entry using forms Objectives, by.
Mark Dixon Page 1 17 – Persistent data storage: relational databases and ADO.
Mark Dixon, SoCCE SOFT 131Page 1 24 – Web applications: Writing data to Databases using ASP.
Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.
NMED 3850 A Advanced Online Design February 25, 2010 V. Mahadevan.
Maintenance Modifying the data –Add records –Delete records –Update records Modifying the design –Add fields into tables –Remove fields from a table –Change.
Mark Dixon Page 1 07 – Reports. Mark Dixon Page 2 Session Aims & Objectives Aims –To use reports to produce more readable documents Objectives, by end.
Mark Dixon Page 1 21 – Object Oriented Programming in ASP.
Mark Dixon, SoCCE SOFT 131Page 1 22 – Web applications: Writing data to Databases using ASP.
Mark Dixon, SoCCE SOFT 131Page 1 16 – Passing Data between pages: Sessions, Query Strings, & Self Posting.
Mark Dixon Page 1 02 – Queries: Query by Example.
Mark Dixon Page 1 20 – Web applications: Writing data to Databases using ASP.
Web Database Programming Week 6 Using Templates & Updating Web Database.
Mark Dixon, SoCCE SOFT 131Page 1 20 – Web applications: Writing data to Databases using ASP.
Database Updates Made Easy In WebFocus Using SQL And HTML Painter Sept 2011 Lender Processing Services 1.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Deleting and Updating Records in MySQL using PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
Mark Dixon Page 1 5 – Persistent data storage: relational databases.
Mark Dixon Page 1 19 – Passing Data between pages: Forms, Sessions, & Query Strings.
Server-side Scripting Powering the webs favourite services.
Mark Dixon Page 1 24 – Object Oriented Programming in ASP.
Mark Dixon Page 1 3 – Web applications: Server-side code (JSP)
Web Services Week 8 Aims: –Using web services as front ends to databases Objectives: –Review of relational databases –Connecting to and querying databases.
Mark Dixon 1 22 – Web applications: Writing data to Databases using ASP.Net.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using ASP.
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.
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.
Mark Dixon Page 1 18 – Web applications: Server-side code (PhP)
Mark Dixon Page 1 21 – Persistent data storage: relational databases and MySQL.
Mark Dixon 1 05 – JSP Databases: Multiple Tables.
Mark Dixon 1 03 – Passing Data between pages: Forms, Sessions, & Query Strings.
Mark Dixon 1 09 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
HTML, PHP, and MySQL: Putting It All Together. Making a Form Input tags Types: “text” “radio” “checkboxes” “submit”
Creating PHPs to Insert, Update, and Delete Data CS 320.
Mark Dixon Page 1 21 – Web applications: Writing data to Databases using ASP.
1 Database Systems Introduction to Microsoft Access Part 2.
Mark Dixon 1 21 – Databases: Multiple Tables. Mark Dixon 2 Questions: Databases How many records are in the following table? How many fields does the.
Mark Dixon 1 21 – Databases: Multiple Tables and Writing Data.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
Mark Dixon Page 1 Soft – HTML. Mark Dixon Page 2 Admin Attendance Register: –log in to your profile.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
Mark Dixon 1 9 – Case Study. Mark Dixon 2 Session Aims and Objectives Aims –To give an overview of the development of a web-page from initial idea to.
Microsoft FrontPage 2003 Illustrated Complete Integrating a Database with a Web Site.
Mark Dixon, SoCCE SOFT 131Page 1 23 – Web applications: Databases & ASP.
MySQL. Is a SQL (Structured Query Language) database server. Can be accessed using PHP with embedded SQL Queries Supports Large DB’s, 60,000 tables with.
Mark Dixon 1 22 – Object Oriented Programming. Mark Dixon 2 Questions: Databases How many primary keys? How many foreign keys? 3 2.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Mark Dixon, SoCCE SOFT 131Page 1 12 – Databases: Structured Query Language.
Invitation to Computer Science 6 th Edition Chapter 10 The Tower of Babel.
CSCI 6962: Server-side Design and Programming Shopping Carts and Databases.
Mark Dixon, SoCCE SOFT 131Page 1 14 – Databases: Multiple Tables.
Web based Documentation Distribution Tools: MSAccess database (DSN) DreamWeaver Ultradev Microsoft Image Composer Clicking on the document will open an.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
18 – Databases: Structured Query Language
Storing Images Connect to the server using the correct username and password. $conn = mysql_connect(“yourserver”, “joeuser”, “yourpass”); Create the database.
Login & administration page
Server-Side Processing II
17 – Persistent data storage: relational databases and ADO
19 – Databases: Multiple Tables
Updating Databases With Open SQL
Updating Databases With Open SQL
Presentation transcript:

Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP

Mark Dixon Page 2 Questions: HTML in PhP Are these correct (assume variables and fields exist)? $f = $f. $r["Description"] $h = $h. $r[" Name"] $a = " " + $a " " $html = $html. $h = " ". $h. " "   

Mark Dixon Page 3 Questions: Databases How many primary keys? How many foreign keys? 3 2

Mark Dixon Page 4 Session Aims & Objectives Aims –To introduce the fundamental ideas involved in using server-side code to write data to databases Objectives, by end of this week’s sessions, you should be able to: –create an ASP web page that allows the user to store data in database

Mark Dixon Page 5 Example: Person v1 (Specification) User requirement: –Display people's details from database online –need 2 pages: smith jones dixon list of people jones sally person's details

Mark Dixon Page 6 Example: PeopleList.php v1 <?php $c = mysql_connect('localhost', 'root', ''); mysql_select_db('People'); $q = mysql_query('SELECT * FROM Person;'); mysql_close($c); $s = ''; while ($r = mysql_fetch_array($q)){ $s = $s. $r['Surname']. ' '; } mysql_free_result($q); ?> <?php Echo $s; ?>

Mark Dixon Page 7 Example: PeopleList.php v2 <?php $c = mysql_connect('localhost', 'root', ''); mysql_select_db('People'); $q = mysql_query('SELECT * FROM Person;'); mysql_close($c); $s = ''; while ($r = mysql_fetch_array($q)){ $s = $s. ' '; $s = $s. $r['Surname']. ' '; } mysql_free_result($q); ?> <?php Echo $s; ?> now links

Mark Dixon Page 8 Example: Person.php v2 <?php $c = mysql_connect('localhost', 'root', ''); mysql_select_db('People'); $sql = "SELECT * FROM Person WHERE id=". $_GET["id"] ; $q = mysql_query($sql); mysql_close($c); $s = ''; if ($r = mysql_fetch_array($q)){ $s = $r['Surname']; } mysql_free_result($q); ?> Back to People List Surname: " /> reads querystring (from previous page) displays data for selected record only

Mark Dixon Page 9 Example: Person v2 (Specification) User requirement: Display person’s details from database online –Change surname and save to database

Mark Dixon Page 10 Changing Data use SQL –INSERT: inserts a new record and makes it current –UPDATE: sends changes back to DB UPDATE Person SET Surname = 'Jones' WHERE ID = 1 –DELETE: deletes currently selected record

Mark Dixon Page 11 Example: Person.php v3 <?php $c = mysql_connect('localhost', 'root', ''); mysql_select_db('People'); $id = $_GET["id"]; if(isset($_POST["btnSave"])){ $sn = $_POST["txtSurname"]; $sql = "UPDATE Person SET Surname = '". $sn. "'"; $sql = $sql. " WHERE ID =". $id; mysql_query($sql); } $sql = "SELECT * FROM Person WHERE id=". $id; $q = mysql_query($sql); mysql_close($c); $s = ''; if ($r = mysql_fetch_array($q)){ $s = $r['Surname']; } mysql_free_result($q); ?> Back to People List Surname: " /> Save button works now

Mark Dixon Page 12 Tutorial Exercise: Person Task 1: Get the Person (v1) example from the lecture working. Task 2: Modify your code, so that forename is displayed as well as surname (use a table). Task 3: Get the Person (v2 and v3) example from the lecture working. Task 3: Modify your code, so that a line of text is displayed confirming that data has been saved. Task 4: Modify your code, so that an add button is included, which allows a new record to be added. Task 5: Modify your code, so that a delete button is included, which allows the current record to be deleted.