Advanced Internet Development Dynamic Web pages with php and MySQL

Slides:



Advertisements
Similar presentations
PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.
Advertisements

PHP and MySQL Database. Connecting to MySQL Note: you need to make sure that you have MySQL software properly installed on your computer before you attempt.
NMD202 Web Scripting Week5. What we will cover today PHPmyAdmin Debugging – using print_r Modifying Data PHP (cont.) 4D Methodology File and IO operations.
Install WordPress with Xampp. By With Thanks to: Rupesh Kumar.
Faculty of Sciences and Social Sciences HOPE PHP & MySQL Stewart Blakeway FML 213
PHP and MySQL PHP for the Web, page PHP and MySQL MySQL Resource PHP – MySQL Resource
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
Dynamic Web site With PHP and MySQL. MySQL The combination of MySQL database and PHP scripting language is optimum for building dynamic websites. MySQL.
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,
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Class 3 MySQL Robert Mudge Reference:
1 Chapter 8 – Working with Databases spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
Slide 8-1 CHAPTER 8 Using Databases with PHP Scripts: Using MySQL Database with PHP.
Internet and Web Application Development Revision.
INTERNET APPLICATION DEVELOPMENT For More visit:
How to create a website with HTML and PHP The very basics By Alexander Niehoff.
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
Nic Shulver, Retrieving Stored Data Introduction This set of slides shows: The information source database structure The data.
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.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
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.
Lecture 10 – MYSQL and PHP (Part 2)
Mark Dixon Page 1 21 – Persistent data storage: relational databases and MySQL.
Database Access with PHP and MySQL CS356 Examples from Web Database Applications, by Hugh E. Williams & David Lane, O'Reilly, 2002.
PHP with MySQL 1.
PHP+MySQL Integration. Connecting to databases One of the most common tasks when working with dynamic webpages is connecting to a database which holds.
CS 174: Web Programming August 31 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Creating PHPs to Insert, Update, and Delete Data CS 320.
Login to a Database (from a Webpage), Inserting data into a database from a form, getting data from database and display on Webpage Done by: Mashail Alsolamy.
PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions.
Dr. Venton Kepuska Donald L. Troup. Dynamic Web Calendar
Enterprise PHP – Reading Data from a DB Reading Data from a relational database in PHP Nic Shulver, FCES, Staffordshire University Using the SQLi interface.
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.
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)
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.
MySQL MySQL and PHP – interacting with a database.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
ITX2000 Remote hosts and web servers Prof. Xiaohong (Sharon) Gao Room: T125 Ext: Week 8 – Review Reference:
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
The Web Wizard’s Guide to PHP by David Lash
Remote hosts and web servers
Introduction to Dynamic Web Programming
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
PHP: Inserting data FdSc Module 109 Server side scripting and
Unix System Administration
Web Design and Development
Web Design and Development
Introduction to Web programming
Website Development Basics with PHP MySQL
PHP Overview PHP: Hypertext Preprocessor Server-Side Scripting
MySQL tutorial.
PHP and MySQL.
Web Systems Development (CSC-215)
MySQL and PHPMyAdmin 1.
Web Programming– UFCFB Lecture
PHP Forms and Databases.
Database Access with PHP and MySQL
Instructor Information: Mark Jamil
Introduction to Web programming
PHP Programming Using Cloud 9 IDE.
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:

Advanced Internet Development Dynamic Web pages with php and MySQL Lecturers Dr Phil Davies Mr Keith Norris

Basic Building Blocks Web Dbase Browser Web Server Web Application Server MySQL Database MySQL RDBMS $conn = mysql_connect(“host”, “user”, “password”); $rs = mysql_select_db($database, $conn) or die(“can’t get into database”); $res1 = mysql_query($query_string); mysql_close($conn);

Development of a Dynamic Web Page info.html Student Number? MySQL Database holding Student Records find_student.php Web Server Apache Search for a Particular Student via Student Number and display it student.html Input Data for DBase Student Name Forename Surname Age Description php Web Application Server student_insert.php Actioned from student.html form input to Insert: Student Name Forename Surname Age Description

Develop a Tutorial that will guide a student at this level through the process of developing such a dynamic web server based system

Setting up Apache/php/MySQL Environment – slight changes Run XAMPP Control Panel Run Apache and MySQL Server Click on Admin – Apache or use localhost:8080 phpMyAdmin > following screen shots mix between XAMPP and Uniform Server

phpMyAdmin

Create a Table Create a Table called student_rec in database student_info_db This will have 5 fields: s_number; s_forename; s_surname; s_age; s_description

Create Table and Populate Record Layout

Table Structure Confirmed To insert student records

Create a Student Record

Create Second Student Record

Search to Check Records

Results of Search

Print View of Results

Development of a Dynamic Web Page info.html Student Number? MySQL Database holding Student Records find_student.php Web Server Apache Search for a Particular Student via Student Number and display it student.html Input Data for DBase Student Name Forename Surname Age Description php Web Application Server student_insert.php Actioned from student.html form input to Insert: Student Name Forename Surname Age Description

student.html – insert a record Will ACTION student_insert.php

Student.html – form for input <head> <title> This is Inputting a Student Record </title> </head> <body> <h1> Form to Permit The Insertion of a New Student</h1> <form method = "post" action = "http://localhost/student_insert.php"> <p><label>Student Number:<input type = "text" name = "s_number" size= "8" maxlength = "8" /></label></p> <p><label>Student Forename:<input type = "text" name = "s_forename" size= "15" maxlength = "15" /></label></p> <p><label>Student Surname:<input type = "text" name = "s_surname" size= "25" maxlength = "25" /></label></p> <p><label>Student age:<input type = "text" name = "s_age" size= "3" maxlength = "3" /></label></p> <p><label>Student Description:<input type = "text" name = "s_description" size= "50" maxlength = "50" /></label></p> <input type= "submit" value = “Insert Record"> </form> </body> </html>

Development of a Dynamic Web Page info.html Student Number MySQL Database holding Student Records find_student.php Web Server Apache Search for a Particular Student via Student Number and display it student.html Input Data for DBase Student Name Forename Surname Age Description php Web Application Server student_insert.php Actioned from student.html form input to Insert: Student Name Forename Surname Age Description

student_insert.php <?php extract($_POST); $username = "root"; $password = ""; $database = "student_info_db"; $host = “localhost”; $conn = mysql_connect($host, $username, $password) or die("sorry"); $rs = mysql_select_db($database, $conn) or die(“can’t get into database”); $query = "INSERT INTO student_rec (s_number, s_forename, s_surname, s_age, s_description) VALUES ('$s_number', '$s_forename', '$s_surname', '$s_age', '$s_description')"; $result = mysql_query( $query) or die ("could not insert record query"); mysql_close($conn); ?>

phpMyAdmin search (3 records)

Development of a Dynamic Web Page info.html Student Number> MySQL Database holding Student Records find_student.php Web Server Apache Search for a Particular Student via Student Number & Display it student.html Input Data for DBase Student Name Forename Surname Age Description php Web Application Server student_insert.php Actioned from student.html form input to Insert: Student Name Forename Surname Age Description

info.html <html> <head> <title> Searching for a Student Record via Student Number</title> </head> <body> <h1> Searching for a Student via Student Number</h1> <form method = "post" action = "http://localhost/find_student.php"> <p><label>Student Number:<input type = "text" name = "s_number" size= "8" maxlength = "8" /></label></p> <input type= "submit" value = "Find Student"> </form> <p> </body> </html>

Development of a Dynamic Web Page info.html Student Number? MySQL Database holding Student Records find_student.php Web Server Apache Search for a Particular Student via Student Number & Display it student.html Input Data for DBase Student Name Forename Surname Age Description php Web Application Server student_insert.php Actioned from student.html form input to Insert: Student Name Forename Surname Age Description

Student.php – display all $username = "root"; $database = "student_info_db"; $host = "localhost"; $password = ""; $conn = mysql_connect($host,$username,$password) or die("sorry"); $rs = mysql_select_db($database, $conn) or die ("sorry - could not connect to the database"); $query = "SELECT * from student_rec"; $res = mysql_query($query); $num_rows = mysql_num_rows($res); for ($i=0; $i<$num_rows; $i++) { $row_array = mysql_fetch_row($res); echo “Student Record Holds “.$row_array[0].”**”.$row_array[1] ].”**”.$row_array[2] .”**”.$row_array[3].”**”.$row_array[4]."<br/>"; } mysql_close($conn); ?>

Display all records (SQL)

Select a Single Student (SQL) find_student.php extract($_POST); $username = "root"; $password = ”"; $database = "student_info_db"; $conn = mysql_connect("localhost",$username,$password) or die("sorry"); $rs = mysql_select_db($database, $conn) or die(“can’t get into database”); $query = "SELECT s_number, s_forename, s_surname, s_age, s_description FROM student_rec WHERE s_number = '". $s_number ."'"; $result = mysql_query($query) or die("could not do query"); if ($result) { $row_array = mysql_fetch_row($res); echo “Student Record Holds “.$row_array[0].”**”.$row_array[1] ].”**”.$row_array[2] .”**”.$row_array[3].”**”.$row_array[4]."<br/>"; } else{ echo "no rows"; mysql_close($conn); ?>

Dynamic Web Page with a bit of style <html> <head> <title> Find a Particular Student </title> <style type="text/css"> p {text-align:center;color:red} h1 {text-align:center;color:blue} </style> </head> ........

External CSS <head> <title> Find a Particular Student </title> <link href="http://localhost/my_style.css" rel="stylesheet" type="text/css" /> </head> External File – my_style.css <style type="text/css"> p {text-align:center;color:red} h1 {text-align:center;color:blue} </style>

External CSS using php <head> <title> Find a Particular Student </title> <link href="http://localhost/my_style.php" rel="stylesheet" type="text/css" /> </head> External File – my_style.php p {text-align:center;color:red} h1 {text-align:center;color:green}

my_style.php <?php $grn = 'green'; ?> <style type="text/css"> p {text-align:center;color:red} h1 {text-align:center;color:<?php echo $grn;?>} </style>

Passing a Parameter to php stylesheet Link from html file <link href="http://localhost/my_style.php?param='green'" rel="stylesheet" type="text/css" /> -------------------------------------------------------------------------- <?php $grn = $_GET['param']; ?> <style type="text/css"> p {text-align:center;color:red} h1 {text-align:center;color:<?php echo $grn;?>} </style>

For your consideration? Can a variable be read from the mqsql file that will cause the web page style sheet to be amended so that a particular response will create a different presentation version of the page to be displayed for different users?