Insert Update and Delete Queries 1 Return to

  • Slides: 39
Download presentation
Insert, Update and Delete Queries 1

Insert, Update and Delete Queries 1

Return to you Address Book database. Insert a record. 2

Return to you Address Book database. Insert a record. 2

Recall that this action provides the SQL, better yet it will provided the PHP

Recall that this action provides the SQL, better yet it will provided the PHP that writes the SQL. 3

Copy the code and put it somewhere for safe keeping 4

Copy the code and put it somewhere for safe keeping 4

Saved PHP-SQL code in Notepad 5

Saved PHP-SQL code in Notepad 5

Mark a record and click the pencil icon to update that record. 6

Mark a record and click the pencil icon to update that record. 6

Change some fields and click Go. 7

Change some fields and click Go. 7

Rats. I didn’t see any SQL Update query to copy. 8

Rats. I didn’t see any SQL Update query to copy. 8

Mark a record and click on the Delete button 9

Mark a record and click on the Delete button 9

Copy the SQL for the DELETE, then decide whether you want to delete this

Copy the SQL for the DELETE, then decide whether you want to delete this record or not. 10

Saved DELETE query 11

Saved DELETE query 11

Start two PHP files, place a form and a table with one row and

Start two PHP files, place a form and a table with one row and two columns on the first page. 12

Add a list/menu and a submit button in column 1 and a radio group

Add a list/menu and a submit button in column 1 and a radio group in column 2. 13

Corresponding code. 14

Corresponding code. 14

Add PHP code for putting names into list/menu. 15

Add PHP code for putting names into list/menu. 15

Result so far. 16

Result so far. 16

Add a second form and second table with 1 row (to start) and 3

Add a second form and second table with 1 row (to start) and 3 columns 17

Corresponding code 18

Corresponding code 18

After the row (</tr>) but before end of table (</table>), start PHP code block.

After the row (</tr>) but before end of table (</table>), start PHP code block. Make array of database filed names. 19

Write a foreach loop that iterates over the Field. Array making a table row

Write a foreach loop that iterates over the Field. Array making a table row corresponding to each 20

Result so far. 21

Result so far. 21

Add SQL query beforeach loop, edit middle column code. 22

Add SQL query beforeach loop, edit middle column code. 22

Result so far 23

Result so far 23

Add non-breaking space (  ) to middle column 24

Add non-breaking space (  ) to middle column 24

After non-breaking space was added to middle column 25

After non-breaking space was added to middle column 25

Add if so no Old data is showing for “Insert” choice 26

Add if so no Old data is showing for “Insert” choice 26

Problem • The radio buttons do not hold onto the information about what choice

Problem • The radio buttons do not hold onto the information about what choice was clicked before. 27

The top form’s action is the same page, so it can refer to its

The top form’s action is the same page, so it can refer to its own $_POST array. I add some php script in the radio button tags to check the appropriate radio button. 28

Add if structure that “remembers” which item from the list was selected The extra

Add if structure that “remembers” which item from the list was selected The extra word selected in the option tag will indicate which of the option should be showing. 29

Added some code so that textboxes are read only and gray when Delete is

Added some code so that textboxes are read only and gray when Delete is the chosen action 30

Remembers selected person, remembers selected action, grays out textboxes when delete is selected action.

Remembers selected person, remembers selected action, grays out textboxes when delete is selected action. 31

Add submit button to bottom form. 32

Add submit button to bottom form. 32

Show old data in textbox (as starting point) when Update is selected action. 33

Show old data in textbox (as starting point) when Update is selected action. 33

Result showing old data in textbox (as starting point) when Update is selected. 34

Result showing old data in textbox (as starting point) when Update is selected. 34

Insert Hidden Fields (to hold info from top form on bottom form so it

Insert Hidden Fields (to hold info from top form on bottom form so it can be passed to handler of bottom form) 35

Result of hidden fields added 36

Result of hidden fields added 36

PHP code to get values from top form onto bottom form 37

PHP code to get values from top form onto bottom form 37

Handler code to determine action requested on calling page 38

Handler code to determine action requested on calling page 38

39

39