CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr

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.
Widhy Hayuhardhika NP, S.Kom. Overview of database structure Connecting to MySQL database Selecting the database to use Using the require_once statement.
Web Database Programming Connecting Database to Web.
Performed by:Gidi Getter Svetlana Klinovsky Supervised by:Viktor Kulikov 08/03/2009.
Database Connectivity in PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
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.
File uploading in PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Database Updates Made Easy In WebFocus Using SQL And HTML Painter Sept 2011 Lender Processing Services 1.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
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.
Create an online booking system (login/registration)
Server-side Scripting Powering the webs favourite services.
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
Chapter 7 PHP Interacts with Ms. Access (Open DataBase Connectivity (ODBC))
INTERNET APPLICATION DEVELOPMENT PRACTICAL ON CONNECTING TO MYSQL.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
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.
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.
1 Mexican Restaurant Prepared by Sandy Nichols November 21, 2006.
PHP with MySQL 1.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
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.
Retrieving data from MySQL using PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions.
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.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
MySQL MySQL and PHP – interacting with a database.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
Web Database Programming Using PHP
Tried my best to simplify it for you!
PHP (Session 2) INFO 257 Supplement.
Databases.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Introduction to Dynamic Web Programming
IS1500: Introduction to Web Development
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Web Database Programming Using PHP
Storing Images Connect to the server using the correct username and password. $conn = mysql_connect(“yourserver”, “joeuser”, “yourpass”); Create the database.
Web Design and Development
Introduction to Web programming
Passing variables between pages
BASIC PHP and MYSQL Edward S. Flores.
PHP Overview PHP: Hypertext Preprocessor Server-Side Scripting
MySQL tutorial.
HTML Forms and User Input
ISC440: Web Programming 2 Server-side Scripting PHP 3
Web Systems Development (CSC-215)
In Class Programming BIS1523 – Lecture 11.
Video list editor BIS1523 – Lecture 24.
Introduction to Web programming
Presentation transcript:

CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr. Tehseen Riaz Abbasi

Web Technologies and Programming Lecture 27

Retrieving Data, Delete, Update from Database

Creating database in MySQL using WAMP Connecting PHP with MySQL Summary of the previous lecture Creating database in MySQL using WAMP Connecting PHP with MySQL Inserting data in database CONNECTIONS: user registration FILES super global variable File uploading in PHP Storing reference of uploaded file in database User registration in CONNECTIONS web application with file upload

Retrieving data from MySQL using PHP CONNECTIONS: login functionality Outline Retrieving data from MySQL using PHP CONNECTIONS: login functionality Deleting records in MySQL using PHP Updating records in MySQL using PHP

Connection with database Execute Select SQL command 1. Retrieving data from MySQL using PHP Connection with database Execute Select SQL command Make display structure Write data

1.1 Connection with database <?php mysql_connect(“localhost”,”root”,””) or die(“Error in connection”); mysql_select_db(“testdatabase”) or die(“Error in Selection”); ?>

The SELECT statement is used to select data from one or more tables: 1.2 Selecting data The SELECT statement is used to select data from one or more tables: SELECT command in SQL: SELECT column-name FROM table-name SELECT user_Name FROM users SELECT *

Condition selection: SELECT column-name FROM table-name 1.2 Selecting data… Condition selection: SELECT column-name FROM table-name WHERE condition SELECT * FROM users WHERE user_Id>4

1.2 Selecting data… <?php include(‘connection.php’); $sql = ‘select * from users’; $result = mysql_query($sql); ?>

include(‘connection.php’); $sql = ‘select * from users’; 1.2 Selecting data… 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 <table border=‘1’> <tr> <th> User Name</th> <th> User Email</th> <th> User Password</th> <th> User Picture</th> </tr> <td>  </td> </table>

mysql_fetch_array(result-resource); 1.4 Writing data mysql_fetch_array(result-resource); mysql_fetch_array($result);

$row = mysql_fetch_array($result); 1.4 Writing data… $result= 1 Ali ali@yahoo.com 123 upload/123ali.jpg 2 Umar umar@yahoo.com 123 upload/123umar.jpg $row = mysql_fetch_array($result); 4 1 2 3 1 Ali ali@yahoo.com 123 upload/123ali.jpg $row= user_Id user_Name user_Email user_Password user_Picture echo $row [1]; echo $row[‘user_Name’];

1.4 Writing data… User Name User Email User Password User Picture Ali ali@yahoo.com 123 <table border=‘1’> <tr> <th> User Name</th> <th> User Email</th> <th> User Password</th> <th> User Picture</th> </tr> <td> <?php echo $row[1]; ?> </td> <td> <?php echo $row[2]; ?> </td> <td> <?php echo $row[3]; ?> </td> <td> <img src= “<?php echo $row[4]; ?>”> </td> </table>

1.4 Writing data… <table border=‘1’> Heading Row <?php while($rows = mysql_fetch_array($result)) { ?> <tr> <td> <?php echo $row[1]; ?> </td> <td> <?php echo $row[2]; ?> </td> <td> <?php echo $row[3]; ?> </td> <td> <img src= “<?php echo $row[3]; ?>”> </td> </tr> <?php } ?> </table> User Name User Email User Password User Picture Ali ali@yahoo.com 123 Umar umar@yahoo.com

Connection to database 1.5 Example Starts a HTML page Connection to database Select command Query executed Counting number of rows

1.5 Example… Heading row Loop starts Keeps row

Displays name Displays email Displays password Displays image 1.5 Example… Displays name Displays email Displays password Displays image Sets source Ends loop Ends table

Records in user’s table 1.5 Example… Records in user’s table Output from the table

Form for user’s input Login action page: Connection with database 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 email 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

2.1 CONNECTIONS: User login form Post method email Password

2.2 CONNECTIONS: database connection <?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

2.4 CONNECTIONS: Select record

Fetch user information 2.5 CONNECTIONS: Redirect No. of rows selected Fetch user information Register session variables redirect If user’s input is invalid

User’s pic User profile User’s information actions 2.6 CONNECTIONS: user page User’s pic User profile User’s information actions

2.6 CONNECTIONS: user page… Image div Profile div User’s info

Connection with database Delete the record 3. Deleting record in MySQL using PHP Connection with database Delete the record

3.1 Connection with database <?php mysql_connect(‘localhost’,’root’,’’) or die(“error in connection”); mysql_select_db(‘testdatabase’) or die(“error in selection”); ?>

Delete SQL instruction: 3.2 Delete the record Delete SQL instruction: DELETE FROM table-name WHERE condition DELETE FROM users WHERE user_Id =5 WHERE user_Id >5

include(‘connection.php’); $sql=“DELETE FROM users WHERE user_Id=5”; 3.2 Delete the record… <?php include(‘connection.php’); $sql=“DELETE FROM users WHERE user_Id=5”; mysql_query($sql); ?>

Display data from database in a table Add actions column 3.3 Example Display data from database in a table Add actions column In each record, add a delete button When delete button in clicked, delete that record

1.3 Example… Delete

3.3 Example… <?php Connection with database Select data <table border=‘1’> <tr> <th> User Name</th> <th> User Email</th> <th> User Password</th> <th> User Picture</th> <th> Actions </th> </tr>

3.3 Example… <?php while($rows = mysql_fetch_array($result)) { ?> <tr> <td> <?php echo $row[1]; ?> </td> <td> <?php echo $row[2]; ?> </td> <td> <?php echo $row[3]; ?> </td> <td> <img src= “<?php echo $row[4]; ?>”> </td> <td><a href=“delet.php?id=<?php echo $rows[0];?>”>Delete</a> </tr> <?php } ?> </table>

3.3 Example… <a href=“delet.php?id=<?php echo $rows[0];?>”> Delete</a> Id name Link starts Page name Assigning the id of current record End of link Link text

Connection to database 3.3 Example… Starts HTML page Connection to database Selecting data

3.3 Example… Heading row Loop starts

3.3 Example… Writing user’s record Link to the delete.php Ends loop

Executing instruction 3.3 Example… Getting record id DB connection Delete instruction Executing instruction

Confirmation before delete: 3.3 Example… Confirmation before delete: Link to page On-click event Confirm box

Connection with database Update the record 4. Updating records in MySQL using PHP Connection with database Update the record

Update SQL instruction: 4. Updating records in MySQL using PHP… Update SQL instruction: UPDATE table-name SET column-names = values WHERE condition UPDATE users SET user_Name = ‘Ali’, user_Email = ‘ali@yahoo.com’, user_Password=‘123’ WHERE user_Id=1

Include(‘connection.php’); 4. Updating records in MySQL using PHP… <?php Include(‘connection.php’); $sql =“UPDATE users SET user_Name = ‘Ali’, user_Email = ‘ali@yahoo.com’, user_Password=‘123 Where user_Id=1’’; mysql_query($sql); ?>

Form with previous values 4.1 Example Selects update Form with previous values

4.1 Example… Values are updated Updated record

View page: Link to update.php, record id is passed with link 4.1 Example… View page: Link to update.php, record id is passed with link

Retrieve record from database against the id Start form 4.1 Example… Get id of the record Connect to database Retrieve record from database against the id Start form Set retrieved values as value of the input fields

HTML page start Gets record’s id DB connection Data selection 4.1 Example… HTML page start Gets record’s id DB connection Data selection Query execution Record is retrieved

Id is sent as hidden value 4.1 Example… Form starts Table starts Id is sent as hidden value label Value is set to user’s current name

4.1 Example… Email password

4.1 Example… Submit button

Execute update instruction Redirect to view page 4.1 Example… Up_action.php page: Retrieve users input Connect with database Execute update instruction Redirect to view page

Connection to database 4.1 Example… User’s input Connection to database Update instruction redirection

5. Limit Data Selections From a MySQL Database MySQL provides a LIMIT clause that is used to specify the number of records to return. The LIMIT clause makes it easy to code multi page results or pagination with SQL, and is very useful on large tables. Returning a large number of records can impact on performance.

$sql = "SELECT * FROM Users LIMIT 30"; 5. Limit Data Selections From a MySQL Database Assume we wish to select all records from 1 - 30 (inclusive) from a table called “users". The SQL query would then look like this: $sql = "SELECT * FROM Users LIMIT 30"; When the SQL query above is run, it will return the first 30 records.

Creating database in MySQL using WAMP Connecting PHP with MySQL Summary of MYSQL DATABASE Intro to MySQL Creating database in MySQL using WAMP Connecting PHP with MySQL Inserting data in database CONNECTIONS: user registration FILES super global variable File uploading in PHP Storing reference of uploaded file in database User registration in CONNECTIONS web application with file upload

Retrieving data from MySQL using PHP Connection with database Summary Retrieving data from MySQL using PHP Connection with database Execute Select SQL command Make display structure Selecting Command Counting rows Write data CONNECTIONS: login page Deleting record in MySQL using PHP Delete the record Delete Command

Updating records in MySQL using PHP Connection with database Summary Updating records in MySQL using PHP Connection with database Update the record Update Command Limit Data Selections

THANK YOU