HTML, PHP, and MySQL: Putting It All Together. Making a Form Input tags Types: “text” “radio” “checkboxes” “submit”

Slides:



Advertisements
Similar presentations
23-Aug-14 HTML/XHTML Forms. 2 What are forms? is just another kind of XHTML/HTML tag Forms are used to create (rather primitive) GUIs on Web pages Usually.
Advertisements

1.  Understanding about How to Working with Server Side Scripting using PHP Framework (CodeIgniter) 2.
Video, audio, embed, iframe, HTML Form
PHP (2) – Functions, Arrays, Databases, and sessions.
PHP and MySQL PHP for the Web, page PHP and MySQL MySQL Resource PHP – MySQL Resource
Objectives Connect to MySQL from PHP
Intermediate PHP & MySQL
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
MS3304: Week 4 PHP & HTML Forms. Overview HTML Forms elements refresher Sending data to a script via an HTML form –The post vs. get methods –Name value.
PHP Security.
Web forms in PHP Forms Recap  Way of allowing user interaction  Allows users to input data that can then be processed by a program / stored in a back-end.
Programming with php By: Seth Larson. A little bit about PHP  PHP stands for PHP:  Hypertext Preprocessor  PHP is a widely-used general-purpose server-side.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
Chapter 4 Handling User Input PHP Programming with MySQL 2nd Edition
PHP : Hypertext Preprocessor
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.
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
1 Insert, Update and Delete Queries. 2 Return to you Address Book database. Insert a record.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
INTERNET APPLICATION DEVELOPMENT For More visit:
1 Forms A form is the usual way that information is gotten from a browser to a server –HTML has tags to create a collection of objects that implement this.
Server-side Scripting Powering the webs favourite services.
INTERNET APPLICATION DEVELOPMENT For More visit:
HTML II. Factors to consider in designing a website. Organizing your files. HTML Tables. Unordered Lists. Ordered Lists. HTML Forms. Learning Objectives.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
PHP meets MySQL.
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
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.
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.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
PHP and MySQL CS How Web Site Architectures Work  User’s browser sends HTTP request.  The request may be a form where the action is to call PHP.
1. Connecting database from PHP 2. Sending query 3. Fetching data 4. Persistent connections 5. Best practices.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
ITCS373: Internet Technology Lecture 5: More HTML.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
HTML FORMS GET/POST METHODS. HTML FORMS HTML Forms HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes,
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.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input.
CSE 154 LECTURE 5: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
>> PHP: Insert Query & Form Processing. Insert Query Step 1: Define Form Variables Step 2: Make DB Connection Step 3: Error Handling Step 4: Define the.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Forms Overview, Query string, Submitting arrays, PHP & HTML, Input types, Redirecting the user Mario Peshev Technical Trainer Software.
+ 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.
Starting BBEdit or Notepad and Opening the HTML File Start BBEdit or Notepad Select Open from the File Menu Open survey1.htm from the Public Folder.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
Creating Web Page Forms COE 201- Computer Proficiency.
CSC 405: Web Application Engineering II8.1 Web programming using PHP What have we learnt? What have we learnt? Underlying technologies of database supported.
Working With Database Library And Helpers. Connecting to your Database First you need to set parameters in you database.php file residing in config folder.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
Day 22, Slide 1 CSE 103 Day 22 Non-students: Please logout by 10:12. Students:
PHP (Session 2) INFO 257 Supplement.
Unix System Administration
How to Write Web Forms By Mimi Opkins.
Passing variables between pages
BASIC PHP and MYSQL Edward S. Flores.
ISC440: Web Programming 2 Server-side Scripting PHP 3
Dr. John P. Abraham Professor UTRGV eCommerce CSCI 6314
PHP and Forms.
Presentation transcript:

HTML, PHP, and MySQL: Putting It All Together

Making a Form Input tags Types: “text” “radio” “checkboxes” “submit”

Making a Form Put multiple “inputs” inside tags. Make the last one a “submit” button.

Text: Buttons: Option 1 Option 2 Checkboxes: Option 1 Option 2 Submit button:

Making the Form Useful Add attributes to the form tag:... Add attributes to the input tags: We will need to make a PHP file.

Request a.php Send back a.html a.php <? Echo “Hello”; ?> PHP Interpreter Rendered PHP In HTML format How a WAMP server gets PHP code to a client browser (Windows Apache MySQL PHP Web Server) Client Browser Rendered PHP In HTML format Hello My SQL Database WAMP Server

What our PHP file needs to do Connect to our database Get that data from the form “Escape” the data so it’s safe Send the data to the database

Beginning the PHP file <?php mysql_connect(“localhost”, “root”, “psswd”); Server AddressUsernamePassword

Getting the data from the form Recall the attributes we added to the form and the inputs: $person = $_POST[`person`]; $ = $_POST[` `];

Sending data to the database mysql_query(“INSERT INTO `mydatabase`.`table1` (`ID`, `Name`, ` `) VALUES (NULL, $name, $ )”); Queries can perform many different functions, including adding to the database, reading from the database, or...

Close the Connection mysql_close(); That’s all there is to it! After inserting the data into the database, put in the code for the page the user should see after sending information to the database, or use the header function to navigate to a different page. header(“Location: index.html”);

A Complete PHP File <?php mysql_connect(“localhost”, “root”, “psswd”); $person = $_POST[`person`]; $ = $_POST[` `]; mysql_query(“INSERT INTO `mydatabase`.`table1` (`ID`, `Name`, ` `) VALUES (NULL, ‘$name’, ‘$ ’)”); mysql_close(); header(“Location: index.html”); ?>

PHP Arrays A PHP array can store pairs of pieces of information (usually numbers or strings). In each pair, one piece of information is called the “key,” and the other is called the “value.” You can create a PHP array like this: $myarray = array( ‘breakfast’ => ‘eggs’, ‘lunch’ => ‘sandwich’, ‘dinner’ => ‘steak’); To retrieve one of the values, use square brackets and the correct key: $food = $myarray[‘breakfast’]”; echo “$food”;

PHP Arrays We used arrays earlier when using the POST method. $person = $_POST[`person`]; $ = $_POST[` `]; PHP automatically created an array called $_POST with the information provided by the user. The ‘name’ attributes from the input tags became the keys of this array.

PHP Arrays To insert information into an array after it’s been created: $myarray[‘snack’] = ‘chips’; If you leave the key field blank, the keys will be integers, auto-incrementing from 0. $myarray[] = ‘Dwayne Wade’; $myarray[] = ‘Lebron James’; $myarray[] = ‘Chris Bosh’; $myarray[0] $myarray[1] $myarray[2]

PHP Arrays You can also omit keys when creating the array… $myarray = array(‘knicks’, ‘heat’, ‘bulls’, ‘cavs’); $myarray[2] or start with an empty array… $myarray = array()

PHP For Loops For loops let you run the same lines of code over and over again. Example: <?php $num = 2; for($i = 0; $i < 10; $i ++){ $num = $num + 3; } echo ‘$num’; ?>

PHP For Loops There are three parts to the definition of a for loop in PHP: 1)Create a variable and give it a starting value. -Usually the variable will start at 0 2)Set a condition for the variable. -i.e. $i < 10, or $i <= 10 -The for loop will not run unless the condition is true. 3)Specify how to change the variable after each iteration. -$i++ is shorthand for making $i go up by 1. -It’s the same thing as $i = $i + 1 for($i = 0; $i < 10; $i ++)

Getting Information From the Database Use the mysql_query() function again. $rs = mysql_query(“SELECT * FROM `mydatabase`.`mytable`”); Now $rs is a MySQL resource. It contains all the information we quested in our select query, but in order to use it, we need to convert it into PHP arrays. The mysql_fetch_array() function converts the first row of the resource into an array. $row1 = mysql_fetch_array($rs); The next time mysql_fetch_array() is called on $rs, it will return the second row. $row2 = mysql_fetch_array($rs);

mysql_fetch_array The keys of the array created by myql_fetch_arrray() can be either the column titles or the column indices (zero-indexed). IDName 1Lebron James 2Dwayne Wade $row1 = mysql_fetch_array($rs); $row2 = mysql_fetch_array($rs); $row1[“Name”] $row1[1] $row2[“Name”] $row2[1] “Lebron James” “Dwayne Wade”

Use a Loop… for($k = 0; $k < 2; $k++){ $row = mysql_fetch_array($rs); $name = $row[“Name”]; echo ‘$name’; } IDName 1Lebron James 2Dwayne Wade

mysql_num_rows The mysql_num_rows() function tells you how many rows are in your MySQL resource. $num = mysql_num_rows($rs); This can be especially useful when used to create a for loop: for($i = 0; $i < $num; $i++){ $row = mysql_fetch_array($rs); $name = $row[“Name”]; echo ‘$name’; }

A Complete PHP File <?php mysql_connect(“localhost”,”root”,”password”); $resource = mysql_query(“SELECT * FROM `mydatabase`.`mytable`”); $n = mysql_num_rows($resource); for($i = 0; $i < $n; $i++){ $row = mysql_fetch_array($rs); $name = $row[“Name”] echo ‘$name’; } mysql_close(); ?>

A Couple More Things to Know How to escape your inputs: $ = mysql_real_escape_string($_POST[` `]); The difference between POST and GET: GET encodes information in the URL. POST encodes information where it can’t be seen by the user. Don’t use GET if it would be a problem if the user submitted the information twice!

Useful Links PHP Arrays: PHP For Loops: List of PHP MySQL-related functions: