Web Design and Development

Slides:



Advertisements
Similar presentations
PHP: Date() Function The PHP date() function formats a timestamp to a more readable date and time.
Advertisements

PHP II Interacting with Database Data. The whole idea of a database-driven website is to enable the content of the site to reside in a database, and to.
PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.
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.
Objectives Connect to MySQL from PHP
Multiple Tiers in Action
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
SJSU CS157B Dr. Lee1  2004 Jenny Mitchell Two Useful Tools You Can’t Live Without by Jenny Mitchell SJSU CS157B Section PHP and MySQL.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
What is MySQL? MySQL is a database. The data in MySQL is stored in database objects called tables. A table is a collections of related data entries and.
© 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.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
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.
INTERNET APPLICATION DEVELOPMENT For More visit:
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
INTERNET APPLICATION DEVELOPMENT PRACTICAL ON CONNECTING TO MYSQL.
MySQL. MySQL is a Relational Database Management System (RDBMS) that runs as a server providing multiuser access to a number of databases. A third party.
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.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
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.
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.
PHP+MySQL Integration. Connecting to databases One of the most common tasks when working with dynamic webpages is connecting to a database which holds.
Creating PHPs to Insert, Update, and Delete Data CS 320.
8 th Semester, Batch 2008 Department Of Computer Science SSUET.
Creating A Database Driven Website 1.Setting Up Your Web Server 2.Creating a Database 3.Creating a Webpage to Display Information From a Database 4.Creating.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
PHP: MySQL. PHP Connect to MySQL PHP 5 and later can work with a MySQL database using: – MySQLi extension (the "i" stands for improved) – PDO (PHP Data.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
Setting up Dreamweaver to use your local WAMP testing Server
CHAPTER 10 PHP MySQL Database
MySQL MySQL and PHP – interacting with a database.
13 – PHP MySQL Connection Informatics Department Parahyangan Catholic University.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free, and efficient alternative.
Nic Shulver, Storing Data on the Server Introduction We are going to look at some working code It writes fixed data into a simple.
Web Systems & Technologies
PHP Built-In Functions
PHP: MySQL Lecture 14 Kanida Sinmai
Y.-H. Chen International College Ming-Chuan University Fall, 2004
CS320 Web and Internet Programming SQL and MySQL
Web Design and Development
IS1500: Introduction to Web Development
Unix System Administration
Introduction to Web programming
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
Web Design and Development
Database application MySQL Database and PhpMyAdmin
mysql and mysql workbench
Introduction to Web programming
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
BASIC PHP and MYSQL Edward S. Flores.
ISC440: Web Programming 2 Server-side Scripting PHP 3
Web Browser server client 3-Tier Architecture Apache web server PHP
MySQL Web Application Connecting to a MySQL database
MIS2502: Data Analytics MySQL and SQL Workbench
Tutorial 6 PHP & MySQL Li Xu
MySQL Web Application Connecting to a MySQL database
Introduction to Web programming
Conection
PHP Programming Using Cloud 9 IDE.
Presentation transcript:

Web Design and Development Lecture # 09 DB Connection and Data Insertion Instructor: Rida Noor Department of Computer Science

Three Layered Architecture * 07/16/96 Three Layered Architecture (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Three Layered Architecture

Create Database and Table in WAMP or XAMPP * 07/16/96 Create Database and Table in WAMP or XAMPP (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Create a Database Start Apache and MySQL services on XAMPP. * 07/16/96 Start Apache and MySQL services on XAMPP. Press Admin as pointed in image to go to phpMyAdmin. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Create a Database * 07/16/96 (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Create a Database Enter Database name and press create button. * 07/16/96 Enter Database name and press create button. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Create a Database * 07/16/96 Enter Database name ‘testdb’ and press create button. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Create a Table * 07/16/96 Enter table name ‘tbl_registration’ , number of fields ‘6’ and press GO button to create table . (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Create a Table * 07/16/96 Enter following fields and their types. Enter length of each field except for fld_date. Select CURRENT_TIMESTAMP value for fld_date in Default column. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Create a Table * 07/16/96 Check the checkbox of A_I that is auto-increament for fld_reg_id press SAVE button. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Create a Table Here you can see the table you have created. * 07/16/96 (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

PHP Connect to MySQL * 07/16/96 (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Why to establish a connection? * 07/16/96 Why to establish a connection? You should establish a connection to the MySQL database. This is an extremely important step because if your script cannot connect to its database, your queries to the database will fail. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

How to establish a connection? * 07/16/96 Create a new php file in Dreamweaver and save it as “connection.php”. Add following code in connection.php file. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Connection Elements $servername ="your_ servername"; * 07/16/96 $servername ="your_ servername"; $username="your_username"; $password="your_password"; $database="your_database_name"; You should replace "your_servername“, "your_username", "your_password" and "your_database_name" with the your MySQL servername, username, password and database that will be used by your script. At this point you may be wondering if it is a security risk to keep your password in the file. You don't need to worry because the PHP source code is processed by the server before being sent to the browser. So the visitor will not see the script's code in the page source. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Create Connection * 07/16/96 Next you should connect your PHP script to the database. This can be done with the new mysqli PHP function: // Create connection new mysqli($servername, $username, $password, $database); This line tells PHP to connect to the MySQL database server at 'localhost' (localhost is the MySQL server which usually runs on the same physical server as your script). (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Check Connection * 07/16/96 After the connection is established you should check whether the connection has been established or not. This can be completed through the following command: // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } else echo "Connected successfully"; This line checks if connection has not been established it will show an error otherwise it will show success message. ‘die’ provides debugging functionality. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Why to Close Connection ??? * 07/16/96 The connection will be closed automatically when the script ends. To close the connection before, use the following: // Close connection mysqli_close($conn); (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

PHP Insert Static Data Into MySQL * 07/16/96 PHP Insert Static Data Into MySQL (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

PHP Insert Data Into MySQL * 07/16/96 After a database and a table have been created, and connection has been established, we can start adding data in table. Here are some syntax rules to follow: The SQL query must be quoted in PHP String values inside the SQL query must be quoted Numeric values must not be quoted The word NULL must not be quoted The INSERT INTO statement is used to add new records to a MySQL table: Syntax: INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...) (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

PHP Insert Data Into MySQL * 07/16/96 In the start of this lecture we created a empty table named "tbl_registration" with six columns: “fld_reg_id”, “fld_email”, “fld_password”, “fld_firstname”, “fld_lastname” and “fld_date”. Now, let us fill the table with data. Note: If a column is AUTO_INCREMENT (like the " fld_reg_id " column) or TIMESTAMP (like the "fld_date" column), it is no need to be specified in the SQL query; MySQL will automatically add the value. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

PHP Insert Data Into MySQL * 07/16/96 Create a new PHP page in Dreamweaver and save its as “signUp.php”. Write following code in signUp.php page. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Include Connection File * 07/16/96 You can write connection code in each php page to connect PHP to MySQL. But this is not a better approach. A better approach is to make one connection file and include that connection file through a single statement as written below in each page instead of writing entire code. // Include connection include 'connection.php'; (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Insert Statement * 07/16/96 Following SQL statement inserts data or record into table. // Insert Query $sql = "INSERT INTO tbl_registration (fld_email, fld_password, fld_firstname, fld_lastname) VALUES ('john@example.com', 'abc123', 'John', 'Doe')"; (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Check Insertion * 07/16/96 Following statement checks whether data has been added successfully or not. //Check Insertion if (mysqli_query($conn, $sql)) { echo "New record created successfully"; } else echo "Error: " . mysqli_error($conn); (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Close Connection * 07/16/96 The connection will be closed automatically when the script ends. To close the connection before, use the following: // Close connection mysqli_close($conn); (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

How to Insert Data Through HTML Form? * 07/16/96 How to Insert Data Through HTML Form? (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Html Design View of Form * 07/16/96 Create an html page in Dreamweaver and save it as “signUp.html”. Design following layout: (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Html Code View of Form * 07/16/96 Go to Code View of form and change names of textfileds, action and method attributes as follow: (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Insert Data Using Form Into MySQL * 07/16/96 Create a new PHP page in Dreamweaver and save its as “signUp.php”. Write following code in signUp.php page. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*