Deleting and Updating Records in MySQL using PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Slides:



Advertisements
Similar presentations
Publication Module using back end interface. Institution Data Entry Add Documents. Edit/Delete Documents that are added but not yet sent to Institution.
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.
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.
Course for teachers covering: HTML, CSS, JavaScript, JQuery PHP, PHP/MySQL
Website Development Working with Databases. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql.
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.
Class 4 PHP MySQL Robert Mudge Reference:
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.
PHP and SQL Server: Queries IST2101. Project Report 4 SQL Queries Due Sunday, 4/5 at 11:59pm Instructions on how to access team webspace and SQL database.
Tables in HTML 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.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Page Layout Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
Server-side Scripting Powering the webs favourite services.
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
INTERNET APPLICATION DEVELOPMENT PRACTICAL ON CONNECTING TO MYSQL.
 Mysql – popular open-source database management system  PHP usually works with Mysql for web- based database applications  LAMP applications—Web-based.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
Adding Image, audio and video files to web pages Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
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.
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.
Database and mySQL Week 07 Dynamic Web TCNJ Jean Chu.
Technology & Management Club Development Software Overview.
Information Management System “ Expert Profile Module" Information Management System “ Expert Profile Module" The Expert Profile module is an integrated.
Looking for simple php script Language: PHP Must be php>>>>> I can not use an other language Budget: $30.0 If more than $30.0 Please do not bid Login page.
Modeling web applications
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.
13. PHP: Insert, View Data. M. Udin Harun Al Rasyid, S.Kom, Ph.D Desain dan Pemrograman.
PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions.
Information Management System “Good Practice Module" Information Management System “Good Practice Module" The Good Practice / Success Stories module is.
1 Database Systems Introduction to Microsoft Access Part 2.
Mediclaim Portal for The Digital Group InfoTech pvt. ltd. Employees
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.
 Empowers to your customer  Product Rating and its Management in Ecommerce Framework  Product Reviews and Management: Collecting customer opinion about.
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.
Information Management System “Institutions Module" Information Management System “Institutions Module" The System management module is an integrated part.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
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.
Information Management System “Project Module" Information Management System “Project Module" The Project module is an integrated part of System. The back.
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,
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Web Design and Development
Passing variables between pages
BASIC PHP and MYSQL Edward S. Flores.
ISC440: Web Programming 2 Server-side Scripting PHP 3
Chapter 8 Working with Databases and MySQL
What is a Database? A collection of data organized in a manner that allows access, retrieval, and use of that data.
Presentation transcript:

Deleting and Updating Records in MySQL using PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1

Summary of the previous lecture Retrieving data from MySQL using PHP CONNECTIONS: login functionality Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 2

Outline Deleting records in MySQL using PHP Updating records in MySQL using PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 3

1. Deleting record in MySQL using PHP Connection with database Delete the record Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 4

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

1.2 Delete the record Delete SQL instruction: DELETE FROM table-name WHERE condition DELETE FROM users WHERE user_Id =5 DELETE FROM users WHERE user_Id >5 Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 6

1.2 Delete the record… <?php include(‘connection.php’); $sql=“DELETE FROM users WHERE user_Id=5”; mysql_query($sql); ?> Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 7

1.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 Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 8

1.3 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 9 Delete

1.3 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 10 <?php Connection with database Select data User Name User User Password User Picture Actions

1.3 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 11 <?php while($rows = mysql_fetch_array($result)) { ?> ”> ”>Delete

1.3 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 12 ”> Delete Link starts Page name Id name Assigning the id of current record Link text End of link

1.3 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 13 Starts HTML page Connection to database Selecting data

1.3 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 14 Heading row Loop starts

1.3 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 15 Writing user’s record Link to the delete.php Ends loop

1.3 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 16 Getting record id DB connection Delete instruction Executing instruction

1.3 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 17 Confirmation before delete: Link to page On-click event Confirm box

2. Updating records in MySQL using PHP Connection with database Update the record Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 18

2. 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_ = user_Password=‘123’ WHERE user_Id=1 Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 19

2. Updating records in MySQL using PHP… <?php Include(‘connection.php’); $sql =“UPDATE users SET user_Name = ‘Ali’, user_ = user_Password=‘123 Where user_Id=1’’; mysql_query($sql); ?> Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 20

2.1 Example Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 21 Selects update Form with previous values

2.1 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 22 Values are updated Updated record

2.1 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 23 Link to update.php, record id is passed with link View page:

2.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 Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 24

2.1 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 25 HTML page start Gets record’s id DB connection Data selection Query execution Record is retrieved

2.1 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 26 Form starts Table starts label Value is set to user’s current name Id is sent as hidden value

2.1 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 27 password

2.1 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 28 Submit button

2.1 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 29 Up_action.php page: Retrieve users input Connect with database Execute update instruction Redirect to view page

2.1 Example… Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 30 User’s input Connection to database Update instruction redirection

Summary Deleting record from tables in MySQL using PHP Updating record in MySQL using PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 31

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. 32