PHP & MySQL Introduction.

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.
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
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.
Keys, Referential Integrity and PHP One to Many on the Web.
PHP (2) – Functions, Arrays, Databases, and sessions.
Intermediate PHP & MySQL
A02 Creating my website NAME ______________. UNIT 2 – A02 – Creating my Website The purpose of this assessment objective is to create 5 web pages containing.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
Advanced Web 2012 Lecture 4 Sean Costain PHP Sean Costain 2012 What is PHP? PHP is a widely-used general-purpose scripting language that is especially.
Databases with PHP A quick introduction. Y’all know SQL and Databases  You put data in  You get data out  You can do processing on it very easily 
1 Insert, Update and Delete Queries. 2 Return to you Address Book database. Insert a record.
Creating A Site Using A Template In Dreamweaver CS6 Cakes R Us!
MySQL + PHP.  Introduction Before you actually start building your database scripts, you must have a database to place information into and read it from.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Creating Effective School and PTA Websites Sam Farnsworth Utah PTA Technology Specialist
PHP meets MySQL.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
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.
Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.
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.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Polling System Part 1 Creating PHP & MySQL Files CIS 254.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
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.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
Course ILT Forms and queries Unit objectives Create forms by using AutoForm and the Form Wizard, and add or modify form headers and footers Open and enter.
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)
Class 3Intro to Databases Class 4 Simple Example of a Database We’re going to build a simple example of a database, which will allow us to register users.
CPSC 203 Introduction to Computers T97 By Jie (Jeff) Gao.
PHP and SQL Server: Connection IST 210: Organization of Data IST2101.
PHP AND SQL SERVER: CONNECTION IST 210: Organization of Data IST210 1.
Intro to WordPress (Using XAMPP)
Brad N Greenwood, PhD MBA
Sessions and cookies MIS 3501 Jeremy Shafer Department of MIS
CHAPTER 5 SERVER SIDE SCRIPTING
Introduction to Dynamic Web Programming
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Arrays: Checkboxes and Textareas
Unix System Administration
Session 4 PHP & MySQL.
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Web Design and Development
Section 17.1 Section 17.2 Add an audio file using HTML
Arrays and files BIS1523 – Lecture 15.
PHP Training at GoLogica in Bangalore
BASIC PHP and MYSQL Edward S. Flores.
Website Development Basics with PHP MySQL
Intro to PHP & Variables
MySQL tutorial.
Cookies BIS1523 – Lecture 23.
HTML Forms and User Input
ISC440: Web Programming 2 Server-side Scripting PHP 3
Web Systems Development (CSC-215)
Working with Headers and Footers
Building Web Applications
Please thank our sponsors!
Sessions and cookies MIS 3501 Jeremy Shafer Department of MIS
A02 Creating my website NAME ______________.
Learning the Basics of Microsoft Word 2010 for Microsoft Windows
Introduction to Web programming
PHP By Prof. B.A.Khivsara Note: The material to prepare this presentation has been taken from internet and are generated only for students reference and.
Presentation transcript:

PHP & MySQL Introduction

A session keeps variables ‘in mind’ after you load a new page It does this in the $_SESSION array You need two extra lines in THE TOP of your pages session_name( “oneword_no_spaces” ); session_start(); This of it as a fridge You put something in de box before you go Take something out after you return

$_SESSION[‘valid_user’] Three steps of login… $_SESSION[‘valid_user’] $_POST[‘submit’] mysql_query()

The proper order

Database > link $query = “SELECT * FROM books”; //execute & loop $row = mysql_fetch_assoc($result); $id = $row[‘id’]; $title = $row[‘title’]; print "<p>".$title." ["; print "<a href='?r=".$id."'>delete print "</a>]<p>\n";

Q: What’s the proper order? Link > Database <?php $remove_id = $_GET['r'] + 0; if ($remove_id > 0 ){ $query = “DELETE FROM books WHERE id=”.$remove_id.” LIMIT 1”; mysql_query( $query ); } ?> Q: What’s the proper order?

Tasks $_GET/$_POST exercise Delete test

Goals You know what a CMS is You’ll create a website from pages stored in a database You’ll create a form to put pages into a database We’ll use the UPDATE statement

Content Management System CMS Content Management System Users Permissions Content Examples UvA DWS Joomla! ( http://www.linux.com/ ) Drupal (http://www.london.gov.uk/ )

Many people can’t write HTML Conforms to company style Why a CMS? Many people can’t write HTML Conforms to company style Makes managing a website easier Who made a page? When? Still relevant? Who can change what? Can be handled from a website Anytime, anyplace, anywhere

Not really, for a small site Handy for us? Not really, for a small site One user Not a lot of content However No more FileZilla for every change No need to copy/paste header & footer Menu makes itself with a bit of programming Limitations We’ll use HTML code Images still need to be uploaded

Table Primary key = id (int, primary key, a.i.) Content is your html code Menu_name is displayed in the menu Level is the horizontal hierarchy Position is the vertical hierarchy / order website.php?page_id=4

Create table if you haven’t done so yet Exercise Create table if you haven’t done so yet Initials + _ + website Insert a few pages in phpMyAdmin Just add some rubbish but pay attention to the level and order so you can check if your menu is properly generated Make a new folder in your website Example: cindy/cms/ Make a new file index.php Example: cindy/cms/index.php

Creating your main page We’ll only use one file to show every page: index.php For now we’ll put header & footer etc all in that file We need a php script with the following Database connection SELECT id, menu_name, position, level Use the results to make the menu SELECT content WHERE id=x Show the current page content

Menu script Animals Welcome Birds level position Bees if ( $row[‘level’] > 1 ){ print “<p class=‘submenu’>”; } else{ print “<p class=‘menu’>”;

Menu script print “<p class=‘menu_”. $row[‘level’].”’>”; print “<a href= ‘index.php?page_id=“. $row[‘id’].”’>”; print $row[‘menu_name’]; print “</a></p>\n”;

Exercise Create table if you haven’t done so yet Insert a few pages in phpMyAdmin Make a new folder in your website Make a new file index.php Make a table for banner, menu, content Add menu and content php

What goes out must go in Now for the input side Form input types Names id will be dealt with by database content > textarea Menu_name > text input Position > text input (for now) Level > radio input or select Names Same as database fields

Add form html, use print for each line Exercise, admin pages Make a new file cms/admin/index.php Add form html, use print for each line

You want to see a list of current pages Below or above comes the form What goes out must go in You want to see a list of current pages Think of book pages Below or above comes the form On submit we add a new page INSERT INTO xyz_website VALUES ( NULL, ‘”.$content.”’, ‘”.$menu_name.”’, “.$level.”, “.$position.” )” Strip & check incoming variables! A delete option would also be nice

Add form html, use print for each line Add insert and delete code Exercise, admin pages Make a new file cms/admin/index.php Add form html, use print for each line Add insert and delete code

You can only add things at the end… Drawbacks You can only add things at the end… Use large numbers for position Recalculate position Last one is better but you’ll need a timestamp Last page that edited and shares a position is the proper one, the stuff below it moves up one position So…

Add form html, use print for each line Add insert and delete code Exercise, admin pages Make a new file cms/admin/index.php Add form html, use print for each line Add insert and delete code Add a new column at the end of your table Name: changed Type: timestamp

On submit we add a new page Drawbacks On submit we add a new page INSERT INTO xyz_website VALUES ( NULL, ‘”.$content.”’, ‘”.$menu_name.”’, “.$level.”, “.$position.”, NOW())” After you insert or delete a record you run UpdatePosition( $row[‘page_id’]; See next page for this function I nicked it from some website and copy/pasted it ever after

UpdatePosition function UpdatePosition( $id ){ //set counter $query = "SET @counter=0"; mysql_query( $query ); //recalculate positions $query = "UPDATE xyz_website SET position = ( SELECT @counter:= @counter+1 ) WHERE id=".$id." ORDER BY position ASC, changed ASC"; }

Add form html, use print for each line Add insert and delete code Exercise, admin pages Make a new file cms/admin/index.php Add form html, use print for each line Add insert and delete code Add a new column at the end of your table Add UpdatePosition()

Goals You know what a CMS is You’ll create a website from pages stored in a database You’ll create a form to put pages into a database We’ll use the UPDATE statement

Think about your CMS and make a list Tasks Think about your CMS and make a list What is really missing and needed? What else do you like to add? Are there any bugs or vulnerabilities? Add a few pages to your CMS Make a nice CSS layout Add a banner The two above could be taken from your site of the previous course

Done