PHP meets MySQL.

Slides:



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

JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
MS-Access XP Lesson 1. Introduction to MS-Access Database Management System Software (DBMS) Store data in databases Database is a collection of table.
KompoZer. This is what KompoZer will look like with a blank document open. As you can see, there are a lot of icons for beginning users. But don't be.
Microsoft SQL Server 2008 From the Program menu choose: Microsoft SQL Server 2008 R2  SQL Server Management Studio. You may see a window indicating the.
Tutorial 8: Developing an Excel Application
Access - Project 1 l What Is a Database? –A Collection of Data –Organized in a manner to allow: »Access »Retrieval »Use of That Data.
PHP (2) – Functions, Arrays, Databases, and sessions.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 2 1 Microsoft Office Access 2003 Tutorial 2 – Creating And Maintaining A.
Tutorial 6 Working with Web Forms
ISP 121 Week 1 Introduction to Databases. ISP 121, Winter Why a database and not a spreadsheet? You have too many separate files or too much data.
XP New Perspectives on Microsoft Office Excel 2003, Second Edition- Tutorial 11 1 Microsoft Office Excel 2003 Tutorial 11 – Importing Data Into Excel.
Creating a Blank Database 1. Open up Microsoft Access 2. Click on Blank document button 3. On the right panel, Specify the location for saving your database.
Creating And Maintaining A Database. 2 Learn the guidelines for designing databases When designing a database, first try to think of all the fields of.
U:/msu/course/cse/103 Day 23, Slide 1 Review of Day 22 What query did you use to search for an actor by name? –Return matches.
Intermediate PHP & MySQL
Microsoft Visual Basic 2012 CHAPTER TEN Incorporating Databases with ADO.NET.
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Figure 1. Hit analysis in 2002 of database-driven web applications Hits by Category in 2002 N = 73,873 Results Reporting 27% GME 26% Research 20% Bed Availability.
Creating Web Page Forms
PHP and SQL Server: Queries IST2101. Project Report 4 SQL Queries Due Sunday, 4/5 at 11:59pm Instructions on how to access team webspace and SQL database.
Introduction to VBA. This is not Introduction to Excel We’re going to assume you have a basic level of familiarity with Excel If you don’t, or you need.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
XP New Perspectives on Microsoft Access 2002 Tutorial 41 Microsoft Access 2002 Tutorial 4 – Creating Forms and Reports.
1 Insert, Update and Delete Queries. 2 Return to you Address Book database. Insert a record.
1 MySQL and phpMyAdmin. 2 Navigate to and log on (username: pmadmin)
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
MAIL MERGE Designing Documents with. Terms Mail Merge: A process that inserts variable information into a standardized document to produce a personalized.
Moodle (Course Management Systems). Assignments 1 Assignments are a refreshingly simple method for collecting student work. They are a simple and flexible.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Microsoft Access Get a green book. Page AC 2 Define Access Define database.
FireRMS NEMSIS (Part 2) Presented by Laura Small FireRMS Quality Assurance.
Management Information Systems MS Access MS Access is an application software that facilitates us to create Database Management Systems (DBMS)
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.
Week 7. Lecture 2 Functions, Arrays, PHP&MySQL. Function with More than one argument and a return statement For a function to return a value, the return.
XP New Perspectives on Microsoft Access 2002 Tutorial 21 Microsoft Access Tutorial 2 – Creating And Maintaining A Database.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 2 1 Microsoft Office Access 2003 Tutorial 2 – Creating And Maintaining A.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
1 Advanced Topics in Access How to create forms and reports Andrew Yu 03/04/2002.
1 Forms. 2 Our goal is to design a form like that shown below.
Database Systems Microsoft Access Practical #1 Creating Tables Nos 215.
Key Applications Module Lesson 21 — Access Essentials
MS Access 2007 Management Information Systems 1. Overview 2  What is MS Access?  Access Terminology  Access Window  Database Window  Create New Database.
ITCS373: Internet Technology Lecture 5: More HTML.
Intro to MySQL 1. Open a browser and enter the following address: It should lead to a log in screen. If your name is.
PHP Form Introduction Getting User Information Text Input.
CSC 240 (Blum)1 Introduction to Data Entry, Queries and Reports.
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
There are seven main components of a database in Access 2000: Tables. Use tables to store database information. Forms Use forms to enter or edit the information.
Microsoft FrontPage 2003 Illustrated Complete Creating a Form.
CCS – Mail Merge Mail Merge This presentation is incomplete without the associated discussion 1 Coloma Community Schools In-service 21 March 2014.
CSC 240 (Blum)1 Introduction to Access CSC 240 (Blum)2 Click on the Access desktop icon or go to Start/Programs/Microsoft Office/Microsoft Office.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 8 – Integrating a Database with a FrontPage.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
CSC 240 (Blum)1 Introduction to Access CSC 240 (Blum)2 Click on the Access desktop icon or go to Start/All Programs/Microsoft Office/Microsoft Office.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
INTRODUCTION TO DATABASES USING MICROSOFT ACCESS Basic Database Terms Create A Database Creating Table Fields Populating a Table Modifying Data Create.
Microsoft Office 2013 Try It! Chapter 4 Storing Data in Access.
Database (Microsoft Access). Database A database is an organized collection of related data about a specific topic or purpose. Examples of databases include:
Decision Analysis Fall Term 2015 Marymount University School of Business Administration Professor Suydam Week 10 Access Basics – Tutorial B; Introduction.
A little PHP. Enter the simple HTML code seen below.
Database application MySQL Database and PhpMyAdmin
Incorporating Databases with ADO.NET
MySQL and MyPHPAdmin.
Incorporating Databases with ADO.NET
Grauer and Barber Series Microsoft Access Chapter One
Presentation transcript:

PHP meets MySQL

Address Book Example Let us create a rather simple, one table database containing names, addresses, phone numbers, etc. Then we will create a PHP site that interfaces with this database. The site will have two pages, the first will have a list of people in the database. The second will be shown after the user selects a person from the list and will display more information about the selected person.

In the test database, use the Create new table area to make a new table. Give it a name. We are all using the same database, so incorporate your name into the table name to prevent conflicts. Enter the number of fields. Mine will have 8 (id, first name, last name, email, office phone, home phone, department, office location).

Possible design of an address book

The ID Field Most database tables should have an primary key – a field (or fields) that can uniquely identify each record in the table. In this case we have chosen the PersonID to serve as the table’s ID. We checked the radio button (first in the row) to indicate that it is a primary key. We chose the type to be CHAR which means that it can include letters (unlike a number) and must be of fixed length (unlike a varchar).

Unique The third column of radio buttons is labeled Unique. If a field is marked as unique, that means no two records in the table can have the same value for that field. Such a field is a candidate key – that is, it could be used as the primary key but some other choice was made. In Banner a person can be identifies by a PIDM, a La Salle ID and a Social Security Number. One will serve as the primary key and the other should be marked as unique. There are no unique fields in our address book example (apart from the primary key)

Index The second column is marked Index. The usual meaning of Index is that you might want to sort on this field. If you indicate that you might want to sort on a field, the DBMS can do some of the work on this task ahead of time, so that it goes faster when requested. (I’m not sure why unique and index are radio buttons – something may be unique and a desirable field for sorting. ???) I selected index on the LastName field.

Field Lengths Try to choose field lengths that are long enough to accommodate the data you anticipate being entered, but that would rule out bad data being entered. A lot of the decisions that go into database design are about data integrity – making sure that the data that gets in there is at least of the correct format.

Phone Numbers? Certain questions arise concerning phone numbers. Are they really numbers? Does one add or subtract them? If they are stored as text (CHAR or VARCHAR), should one store the formatting. Does one store 2155551234? Or does one store (215) 555-1234?

NULL or NOT NULL One more decision regarding the fields in the table is whether or not a NULL value is allowed for the field. For the field designated as a primary key, the answer is a resounding NO. Since we are interested in integrity, forcing someone to enter data because the field is NOT NULL might make it more likely that they enter bad data. It is not always just a question of whether or not a field should have a value but a practical one of whether the data-entry person will know it. Is it meaningful to have the record with this field NULL?

Click on Save

In the table below, I allowed a lot of fields to be NULL, I didn’t want to eliminate a record because any one piece of information is missing. If you are unhappy with your design decisions, you can click on the pencil icon for a field which will give you the option to edit the design.

Should you decide to collect more data about a person, you can add fields.

To start entering data, click on the Insert button.

Enter the values for your record in the Value column Make sure to put data in the Value column, the function column can throw one off at first. Also a little weird is this second record that gets “ignored.”

Click Go to enter the record, make your radio button choice depending on whether you have more data to enter or not.

As with any database action, it can be achieved using a SQL statement, which the interface shows you. This can be useful later on if you are designing an interface for data entry. Again it even provides the PHP.

View records, click on the table button on left, and then on Browse button at top.

Start two pages, one for the user to choose a name and the second to handle the request. Look ma, I’m trying to be XHTML compliant.

Set some Page Properties, the Title, and then insert a form on the first page.

Choose an action and a method for the form. We’ll try GET this time. The form will have a drop-down list of names. The values will be the IDS. Thus the use of GET may be a security issue. If you think that your Ids should be kept more private, use POST.

Add a menu/list to the page. Give it a name.

To center the menu, go to code, place <div> tags around the select tags and set the div’s align attribute to “center”

Let us add one option to remind ourselves what the HTML for an option looks like.

Turn that into a comment, we want our options to come from the database.

Start a PHP code block with the select tags.

Add a statement to aid in debugging.

Assign some database related variables

Use the function for connecting to MySQL. die(): is a function that will allow you (possibly) to display a message and then get out of the script. With some errors one might desire the script to continue, with others one just wants to get out of the script. The die() function is used in the latter case.

Use the function for selecting the database In the database select function, the database connection variable is an optional parameter. (You might need it if you were connecting to multiple databases.)

Assign to the $sql variable a string containing the SQL query and then use the function to execute the query. Remember the pma interface would provide you with the php for various queries that were performed on the database through the interface. So the assignment statement could be a copy/paste in some circumstances.

Loop through the query results and print out the result into HTML option tags. Note that the harder (less familiar) part here is the while loop with its row array and mysql_fetch_array function. However, it occurs often and is usually the same thing each time.

Result of records coming from database and being placed into options of a drop-down list (menu)

Insert a button below the drop-down list

Give it a name, a label and an action.

In the handler file, set up page properties, insert a header

Result of header tag insert.

Start a PHP block with the <h2> tags

Copy the database related code from the previous file

Edit the query to select data corresponding to the person chosen

Return to AddressBook, add a target to the form

Handler does not replace origin