PHP: Inserting data FdSc Module 109 Server side scripting and

Slides:



Advertisements
Similar presentations
Dreamweaver Forms Overview. Forms – A Little Review Most user/webpage communication is one way, like this: Most user/webpage communication is one way,
Advertisements

Video, audio, embed, iframe, HTML Form
Multiple Tiers in Action
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
Uploading Files. Why? By giving a user the option to upload a file you are creating an interactive page You can enable users have a greater web experience.
Chapter 10 Form Basics Key Concepts Copyright © 2013 Terry Ann Morris, Ed.D 1.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
© 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.
G053 - Lecture 17 Making Forms Work Mr C Johnston ICT Teacher
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
A little PHP. Enter the simple HTML code seen below.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Technology & Management Club Development Software Overview.
© Anselm Spoerri Web Design Information Visualization Course Prof. Anselm Spoerri
Website Development with PHP and MySQL Saving Data.
Accessing Your MySQL Database from the Web with PHP (Ch 11) 1.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.
Creating PHPs to Insert, Update, and Delete Data CS 320.
Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
HTML Form Widgets. Review: HTML Forms HTML forms are used to create web pages that accept user input Forms allow the user to communicate information back.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
+ FORMS HTML forms are used to pass data to a server. begins and ends a form Forms are made up of input elements Every input element has a name and value.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
HTML FORMS The TEXT Object Presented By: Ankit Gupta.
Higher Computing Science Coding the Web: HTML, JavaScript, PHP and MySQL.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
Web Forms. Web Forms: A form allows our web visitors to submit information to us. Some examples uses for forms are to let the web user contact us, fill.
Dreamweaver - Forms questionnaire, register, login, etc.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
CHAPTER 5 SERVER SIDE SCRIPTING
Introduction to Dynamic Web Programming
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
PHP: Forms FdSc Module 109 Server side scripting and Database design
How to Write Web Forms By Mimi Opkins.
18 – Web applications: Server-side code (PhP)
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
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 ©
Section 17.1 Section 17.2 Add an audio file using HTML
Passing variables between pages
BASIC PHP and MYSQL Edward S. Flores.
Website Development Basics with PHP MySQL
Basic Contact Form user sends an
Advanced Internet Development Dynamic Web pages with php and MySQL
DB Programming on the Web
PHP: Output Formatting
PHP Overview PHP: Hypertext Preprocessor Server-Side Scripting
MySQL tutorial.
HTML Forms and User Input
Unit I: Collecting Data with Forms
PHP: Security issues FdSc Module 109 Server side scripting and
Web Development & Design Foundations with H T M L 5
Accessing Your MySQL Database from the Web with PHP (Ch 11)
Server-Side Processing II
PHP: Database Basic Selection FdSc Module 109
PHP: Combo box FdSc Module 109 Server side scripting and
PHP: Database connection
PHP Forms and Databases.
HTML Forms What are clients? What are servers?
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:

PHP: Inserting data FdSc Module 109 Server side scripting and Database design 2011

Today’s achievements Demonstrate knowledge of PHP Accepting Post data from an HTML form Creating a valid SQL Insert statement using the Post data Using PHP functions to update a MySQL database table Creating the input forms and PHP files for the help centre

Create an HTML form We will be inserting a new book into the books table of the library database We will need an HTML form to collect the data We will use a submit button to call a PHP file which will process the data and run the SQL Query to insert the data

Input process CLIENT SERVER PHP FILE MySQL Post sends data to PHP file Input box PHP FILE Submit button PHP sends SQL query to MySQL MySQL

The form HTML forms begin with: Labels are defined by: <form> and end with </form> Method = “post” tells the server to send the data Action = “file.php” tells the server which file to run when the form is submitted Labels are defined by: <label for “fieldname“>Your text</label> Input text fields are defined by <input type="text" id="ISBN" name="ISBN" />

HTML for the form (one box) <body> <form method="post" action="addabook.php"> <label for "ISBN">ISBN:</label> <input type="text" id="ISBN" name="ISBN" /> </form> </body>

Single box Looks similar to: ISBN:

More input boxes We need boxes for all the fields in the books table (apart from bookid). Note the <br /> <label for "ISBN">ISBN:</label> <input type="text" id="ISBN" name="ISBN" /><br /> <label for "title">Title:</label> <input type="text" id="title" name="title" /><br /> <label for "author">Author:</label> <input type="text" id="author" name="author" /><br /> <label for "publisher">Publisher:</label> <input type="text" id="publisher" name="publisher" /><br /> <label for "publisherswebsite">Publisher's Web Site:</label> <input type="text" id="publisherswebsite" name="publisherswebsite" /><br /> <label for "genre">Genre:</label> <input type="text" id="genre" name="genre" /><br />

The submit button We add a button to submit the form to the php file we specified in the action <input type="submit" value="Add a book" name="submit" /> It goes at the end of the other inputs and before the end form tag The value appears on the button

Submit button added <label for "genre">Genre:</label> <input type="text" id="genre" name="genre" /><br /> <input type="submit" value="Add a book" name="submit" /> </form>

Form appearance You can use CSS to tidy this up (but I haven’t) What will happen when you press the button?

The PHP file (addabook.php) Post data is in the array $_POST[‘fieldname'] We assign the values from the form to variables <?php $ISBN = $_POST['ISBN']; $title = $_POST['title']; $author = $_POST['author']; $publisher = $_POST['publisher']; $publisherswebsite = $_POST['publisherswebsite']; $genre = $_POST['genre']; ?>

Check that they were received using echo echo 'Your ISBN number was ' . $ISBN . '<br />'; echo 'Your book title was ' . $title . '<br />'; echo 'Your author was ' . $author . '<br />'; echo 'Your publisher was ' . $publisher . '<br />'; echo 'Your web site was ' . $publisherswebsite . '<br />'; echo 'Your genre was ' . $genre . '<br />';

Add to the database $hostname = “localhost"; $username = “MISNumber"; $password = “XXXXXX"; $databaseName = “MISNumber_library"; include("connection.php"); if ($connectionSuccess == 1) { $query = "INSERT INTO books (ISBN,title, author, publisher, publisherswebsite, genre)" . "VALUES ('$ISBN', '$title', '$author', '$publisher', '$publisherswebsite', '$genre')"; $result = mysql_query($query);

Complete PHP <?php $ISBN = $_POST['ISBN']; $title = $_POST['title']; $author = $_POST['author']; $publisher = $_POST['publisher']; $publisherswebsite = $_POST['publisherswebsite']; $genre = $_POST['genre']; echo 'Your ISBN number was ' . $ISBN . '<br />'; echo 'Your book title was ' . $title . '<br />'; echo 'Your author was ' . $author . '<br />'; echo 'Your publisher was ' . $publisher . '<br />'; echo 'Your web site was ' . $publisherswebsite . '<br />'; echo 'Your genre was ' . $genre . '<br />'; $hostname = “localhost"; $username = “MISNumber"; $password = “XXXXXX"; $databaseName = “MISNumber_library"; include("connection.php"); if ($connectionSuccess == 1) { $query = "INSERT INTO books (ISBN,title, author, publisher, publisherswebsite, genre)" . "VALUES ('$ISBN', '$title', '$author', '$publisher', '$publisherswebsite', '$genre')"; $result = mysql_query($query); } ?>

Check results in PHPMyAdmin

Exercises Create input forms to add data to your help centre database Check they work Use CSS to improve your web pages