Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced Internet Development Dynamic Web pages with php and MySQL

Similar presentations


Presentation on theme: "Advanced Internet Development Dynamic Web pages with php and MySQL"— Presentation transcript:

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

2 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);

3 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

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

5 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

6 phpMyAdmin

7 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

8 Create Table and Populate Record Layout

9 Table Structure Confirmed
To insert student records

10 Create a Student Record

11 Create Second Student Record

12 Search to Check Records

13 Results of Search

14 Print View of Results

15 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

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

17 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 = " <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>

18 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

19 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); ?>

20 phpMyAdmin search (3 records)

21 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

22 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 = " <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>

23 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

24 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); ?>

25 Display all records (SQL)

26 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); ?>

27 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>

28

29 External CSS <head>
<title> Find a Particular Student </title> <link href=" 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>

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

31 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>

32 Passing a Parameter to php stylesheet
Link from html file <link href=" 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>

33 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?

34


Download ppt "Advanced Internet Development Dynamic Web pages with php and MySQL"

Similar presentations


Ads by Google