We help IT Professionals succeed at work.
Get Started

Curious how Expert Awards are earned? Find out on this week's podcast, featuring Experts Exchange CEO Randy Redberg.Listen Now

x
Troubleshooting Question

PHP separation of concerns - am I close?!

Colin Brazier
on
25 Views
Last Modified: 2020-11-27
I'm refactoring my PHP website.  At the moment I am focusing on separation of concerns, because when I wrote it 15 years ago I never considered this and it's making life very difficult when I need to maintain it. Of all the faults it has, this is what would provide the biggest benefit if solved.

I have read and watched tutorials on MVC and have reworked one of my programs trying to separate views from data etc.  This is to update the number of goals scored by each player in a team.  Firstly, I need to know which team the user wants to update, then bring up an editable list of players who have scored goals for that team this season, with another 3 blank lines to add any new scorers.  Finally, after a bit of validation, I update the database.

The code provided is what I have made of it so far. Am I working along the right lines?  What folder structure should I adopt for example?

I don't want to use a commercial framework as it would be overkill for this site, and I want to understand and learn how it all works.

I thought I would ask at this stage because there are another dozen or so CRUD processes along the same lines and I want to start off right.

Oh, and it's all written procedurally; the plan is to bring OOP in at a later stage.

Thanks for reading.

<?php
set_include_path('C:\xampp\htdocs5 - PDO');
require_once("../includes/initialise.php");  // This now only gives the file structure - not the database stuff.
require_once(INC_PATH.DS.'fobgdb.inc');   // gives us our connection, $conn.

require_once(CLASS_PATH.DS.'fobg_html.php'); // need this now?
// load FOBG-specific functions next 
require_once(CLASS_PATH.DS.'fobg_functions.php'); // this is where all the SQL queries live.

$page_title = 'Scorers Edit';   

if (isset($_POST['hdnSide']))   // Do we have the user hitting Submit to update the info?
{
   include(INC_PATH.DS.'scorers_update.php');
   exit();
}

require_once(HTML_PATH.DS.'admin_header.php');

if (empty($_GET) && empty($_POST)) 
{  // no data passed by get or posted, so we need to select a team.
   $arr_teams = getCurrentTeams($conn); 
   // brings up the team list which is used in...
   include(HTML_PATH.DS.'team_selection.php');
   exit();
}

if (isset($_POST['fobgteamgroup']))  // team selection posted, so we need to list and update the scorers in that team.
{
   $side = $_POST['fobgteamgroup'];
   /************************************************************/
   // Get the current season
   $current_season = getCurrentSeason($conn);

   // current season is used in...
   /************************************************************/
   // Get relevant team/season combo data.
   $arr_team_season = getTeamSeason($conn, $side, $current_season);
   extract($arr_team_season);
   
   /************************************************************/
   // Get existing scorers (if any).
   $arr_scorers = getScorers($conn, $side, $current_season);
      
   include(HTML_PATH.DS.'scorers_edit.php');  // show to use to update/add.
   exit();
   /************************************************************/
}

require_once(HTML_PATH.DS.'admin_footer.html');
Comment
Watch Question
Developer
CERTIFIED EXPERT
Fellow
Top Expert 2013
Commented:
This problem has been solved!
Unlock 2 Answers and 6 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE