Web Design and Development Lecture 12 Update Record

Web Design and Development Lecture # 12 Update Record And Introduction To Form Validation Instructor: Rida Noor Department of Computer Science

PHP Update Record

Update Data In a My. SQL Table �The UPDATE statement is used to update existing records in a table: �Syntax: UPDATE table_name SET column 1=value, column 2=value 2, . . . WHERE some_column=some_value �Notice the WHERE clause in the UPDATE 3 syntax: The WHERE clause specifies which record or records that should be updated. If you omit the WHERE clause, all records will be updated!

Update Data In a My. SQL Table �Example �UPDATE tbl_registration SET fld_firstname=‘John’ , fld_lastname ='Doe' WHERE fld_reg_id =2; 4

Create Database and Table in WAMP or XAMPP

Create a Database �Start Apache and My. SQL services on XAMPP. �Press Admin as pointed in image to go to php. My. Admin. 6

Create a Database 7

Create a Database �Enter Database name and press create button. 8

Create a Database �Enter Database name ‘testdb’ and press create button. 9

Create a Table �Enter table name ‘tbl_registration’ , number of fields ‘ 6’ and press GO button to create table. 10

Create a Table �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. 11

Create a Table �Check the checkbox of A_I that is auto-increament for fld_reg_id press SAVE button. 12

Create a Table �Here you can see the table you have created. 13

PHP Connect to My. SQL

Why to establish a connection? �You should establish a connection to the My. SQL database. �This is an extremely important step because if your script cannot connect to its database, your queries to the database will fail. 15

How to establish a connection? �Create a new php file in Dreamweaver and save its “connection. php”. �Add following code in connection. php file. 16

Check Connection �Execute connection. php page in browser and check if it display success message or not. 17

PHP Update Record

PHP Update Static Record �Create a new php page. Save update. Record. php. Write following update. Record. php page. 19 it as code

PHP Update Static Record Check My. SQL records: Execute update. Record. php page in browser: Check My. SQL execution: 20 records after update. Record. php

PHP Update Record Using Form

HTMLChange Password Form �Create a new html page. Save it as change. Password. Form. html. �Create a form in change. Password. Form. html page as follow. 22

PHP Change Password Form �Click on the code view of change. Password. Form. html page and change the following attributes. 23

PHP Change Password Code �Create a new php page. Save it as change. Passwor. Code. php. Write following code in it. 24

HTML Form Validation �HTML form validation can be done by a Java. Script. �If a form field (e. g email) is empty, Java. Script function alerts a message, and returns false, to prevent the form from being submitted: 25

PHP Form Validation �Write following Java. Script in head section of change. Password. Form. html page. 26

PHP Update Password My. SQL records: Enter intended inputs: 27

If Update Is Successful MYSQL RECORDS IF Update IS NOT SUCCESSFUL 28
- Slides: 28