Day 41: PHP update

Dan Esmail - 2/10/2023

Intro

For the final item on my to-do list with the workout post page, I needed to find a way to insert all the information from the work post HTML into the database. This is of course done with PHP and I have done a single row before but never anything on this kind of scale.

The Project

When working with PHP, JavaScript, and HTML I had a few issues but not a ton. One of the issues that I ran into was that if you use the disabled attribute for an input box it ends up blocking the PHP from reading. This caused a lot of confusion when I was trying to pull the date. I ended up changing my JavaScript a tiny bit to make up for this. All I had to do was delete where I had disabled it.

The next thing was to build out the PHP. this had some issues but was relatively easy after doing a lot of testing. I found a good snippet of code that would give me all the keys when using the POST method with my PHP.


PHP
POST Keys

                
                    
      
foreach ($_POST as $key => $value) { echo 'Field '.htmlspecialchars($key).' is '.htmlspecialchars($value). '< br>'; }
            
      
                
            

PHP
POST Keys

                
                    
      
foreach ($_POST as $key => $value) { echo 'Field '.htmlspecialchars($key).' is '.htmlspecialchars($value). '< br>'; }
            
      
                
            

After I found all the names for the form I was able to move on to the next part of the code that I needed to work on. I needed to create two for loops to access all the information from each block of the workout. This was to get the reps and weight for each. I know that five sets were the max that I allowed. Knowing let me do a little bit of math to get each input incrementally. After that, I could send the data to the database as long as the information wasn't blank.

After I found all the names for the form I was able to move on to the next part of the code that I needed to work on. I needed to create two for loops to access all the information from each block of the workout. This was to get the reps and weight for each. I know that five sets were the max that I allowed. Knowing let me do a little bit of math to get each input incrementally. After that, I could send the data to the database as long as the information wasn't blank.


Day 1

Day 1