From the course: PHP for Web Designers
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Organizing the form data into arrays - PHP Tutorial
From the course: PHP for Web Designers
Organizing the form data into arrays
Now that we've seen how to find and extract a substring from a longer string, we can return to order.php in the Hansel and Petal site, and organize the form data into new arrays. First we need to create three empty arrays for color, quantity, and image. We only want those arrays if the form has been submitted, so we'll put them inside this if block here. I'm not going to delete this code here on lines three, four, and five, because we'll use that later for some testing. So our new arrays, first one will be color, and I'm going to use the array keyword to create the empty array. This will work on all servers, of course if you are using PHP 5.4 or later on your server you can use the shorthand version, this will work everywhere. So, that's why I'm using the keyword, and then the last one wil be image. Next we need to go through the post array and we'll use a foreach loop to handle it looking at each key and each value so foreach all one word. And the array is $_POST, all in caps. And…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Getting form input sent by the POST method4m 48s
-
Retrieving values from a URL's query string4m 8s
-
(Locked)
Challenge: Plan the order form2m 28s
-
(Locked)
Solution: Plan the order form4m 42s
-
(Locked)
Finding and extracting a substring7m 38s
-
(Locked)
Organizing the form data into arrays7m 15s
-
(Locked)
Using a loop to build a table for the data4m 42s
-
(Locked)
Controlling which rows are displayed7m 45s
-
(Locked)
Creating a custom function to extract part of a file name7m 43s
-
(Locked)
Calculating the order total6m 34s
-
(Locked)
Using PHP sessions to preserve data3m 14s
-
(Locked)
Storing data in session variables7m 33s
-
(Locked)
Ending the PHP session and deleting the data5m 37s
-
(Locked)
-
-
-