Retrieving data from MySQL using PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Slides:



Advertisements
Similar presentations
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.
Advertisements

PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.
CHAPTER 10 COMMON PROGRAMMING TECHNIQUES. SENDING VALUES TO A SCRIPT Hidden form input type: Depending on the method, $_POST['do'] or $_GET['do'] will.
Web Database Programming Connecting Database to Web.
Faculty of Sciences and Social Sciences HOPE PHP & MySQL Stewart Blakeway FML 213
NAVY Research Group Department of Computer Science Faculty of Electrical Engineering and Computer Science VŠB-TUO 17. listopadu Ostrava-Poruba.
Validating user input Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Database Connectivity in PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Introduction to PHP (Part-1) Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
File uploading in PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
Deleting and Updating Records in MySQL using PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
© 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.
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:
Create an online booking system (login/registration)
Page Layout Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
INTERNET APPLICATION DEVELOPMENT PRACTICAL ON CONNECTING TO MYSQL.
PHP and MySQL for Client-Server Database Interaction Chapter 10.
Working with background, images and date object Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
Adding Image, audio and video files to web pages Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
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.
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.
INTERNET APPLICATION DEVELOPMENT Practical on Sessions.
Lecture 10 – MYSQL and PHP (Part 2)
Technology & Management Club Development Software Overview.
1 Mexican Restaurant Prepared by Sandy Nichols November 21, 2006.
Chapter 6: Authentications. Training Course, CS, NCTU 2 Overview  Getting Username and Password  Verifying Username and Password  Keeping The Verification.
ECE 3553 Final Project by Brian Robl. What is Eventor? A simple, yet effective, website for event planning and searching.  Influence from Facebook Events.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Modeling web applications
Session 7: Getting PHP to Talk to MySQL. Objectives Connecting to the Database Building & Executing the SQL SELECT Query Fetching & Displaying the data.
Intro to DatabasesClass 4 SQL REVIEW To talk to the database, you have to use SQL SQL is used by many databases, not just MySQL. SQL stands for Structured.
Creating PHPs to Insert, Update, and Delete Data CS 320.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions.
PHP and Mysql Database. PHP and Database Mysql – popular open-source database management system PHP usually works with Mysql for web-based database applications.
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
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.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
PHP and SQL Server: Connection IST2101. Typical web application interaction (php, jsp…) database drivers 2IST210.
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.
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.
HTML FORMS Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan. 1.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
© 2007 by Prentice Hall2-1 Introduction to Oracle 10g Chapter 2 Overview of SQL and SQL*Plus James Perry and Gerald Post.
MySQL MySQL and PHP – interacting with a database.
HTML 5 Form elements Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
HTML DOM Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
HTML Links and navigation Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
OBJECTIVES Learn how to view data using SQL and PHP Learn how to add new data using SQL and PHP PHP+SQL: View and Adding,
PHP and SQL Server: Connection IST 210: Organization of Data IST2101.
Web Database Programming Using PHP
Tried my best to simplify it for you!
PHP (Session 2) INFO 257 Supplement.
Introduction to Dynamic Web Programming
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Web Database Programming Using PHP
Web Design and Development
Passing variables between pages
ISC440: Web Programming 2 Server-side Scripting PHP 3
PHP: Database Basic Selection FdSc Module 109
Presentation transcript:

Retrieving data from MySQL using PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1

Summary of the previous lecture FILES super global variable File uploading in PHP Storing reference of uploaded file in database CONNECTIONS: user registration with file upload Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 2

Outline Retrieving data from MySQL using PHP CONNECTIONS: login functionality Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 3

1. Retrieving data from MySQL using PHP Connection with database Execute Select SQL command Make display structure Write data Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 4

1.1 Connection with database Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 5 <?php mysql_connect(“localhost”,”root”,””) or die(“Error in connection”); mysql_select_db(“testdatabase”) or die(“Error in Selection”); ?>

1.2 Selecting data Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 6 SELECT command in SQL: SELECT column-name FROM table-name SELECT user_Name FROM users SELECT * FROM users

1.2 Selecting data… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 7 Condition selection: SELECT column-name FROM table-name WHERE condition SELECT * FROM users WHERE user_Id>4

1.2 Selecting data… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 8 <?php include(‘connection.php’); $sql = ‘select * from users’; $result = mysql_query($sql); ?>

1.2 Selecting data… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 9 Counting rows: – mysql_num_rows(variable); <?php include(‘connection.php’); $sql = ‘select * from users’; $result = mysql_query($sql); $users = mysql_num_rows($result); echo “There are total ”. $users.”users found”; ?>

1.3 Display structure Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 10 User Name User User Password User Picture

1.4 Writing data Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 11 mysql_fetch_array(result-resource); – mysql_fetch_array($result);

1.4 Writing data… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 12 $result= $row = mysql_fetch_array($result); $row= user_Iduser_Name user_ user_Passworduser_Picture echo $row [1]; echo $row[‘user_Name’];

1.4 Writing data… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 13 User Name User User Password User Picture ”> User NameUser User PasswordUser Picture

1.4 Writing data… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 14 Heading Row <?php while($rows = mysql_fetch_array($result)) { ?> ”> User NameUser User PasswordUser Picture om 123

1.5 Example Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 15 Starts a HTML page Connection to database Select command Query executed Counting number of rows

1.5 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 16 Heading row Loop startsKeeps row

1.5 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 17 Displays name Displays Displays password Displays image Sets source Ends loop Ends table

1.5 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 18 Records in user’s table Output from the table

2. CONNECTIONS: User login Form for user’s input Login action page: – Connection with database – Retrieve user’s input – Select a record from user’s table with same and password – Count the number of row in result – If one row is selected then fetch its values and store in session variable, otherwise send an error message on main page Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 19

2.1 CONNECTIONS: User login form Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 20 Password Post method

2.2 CONNECTIONS: database connection Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 21 <?php mysql_connect(“localhost”,”root”,””) or die(“Error in connection”); mysql_select_db(“testdatabase”) or die(“Error in Selection”); ?>

2.3 CONNECTIONS: Retrieve user’s input Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 22

2.4 CONNECTIONS: Select record Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 23

2.5 CONNECTIONS: Redirect Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 24 No. of rows selected Fetch user information Register session variables redirect If user’s input is invalid

2.6 CONNECTIONS: user page Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 25 User profile User’s pic User’s information actions

2.6 CONNECTIONS: user page… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 26 Profile div Image div User’s info ‘picture’

Summary Retrieving data from MySQL using PHP CONNECTIONS: login page Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 27

References Chapter 30, “Beginning PHP and MySQL” by W. Jason Gilmore, Apress publisher, 4th edition; 2010, ISBN-13 (electronic): Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 28