IM trying to move away from procedural code and starting to get my feet wet with OOP, it is slow going but I am learning. I would like some help / opinion on the following:
Consider The Following View / HTML page which creates a simple form
An extract of the Class CreateJob{}
I created looks like this:
function uploadJob($category, $headline, $description, $location){
$sql ="INSERT INTO jobs (category, headline, description, location)
VALUES(:category, :headline, :description, :location)";
$stmnt = $db->prepare($sql);
$stmnt->bindValue(':category', $category);
$stmnt->bindValue(':headline', $headline);
$stmnt->bindValue(':description', $description);
$stmnt->bindValue(':location', $location);
$stmnt->execute();
if($stmnt->rowCount() > 0){
return $success = "Job Successfully Created";
}
else{
return $error = 'SOMETHING WENT WRONG';
}
}
When the form is submitted the following is triggered via isset()
and the object $newJob
is created
if(isset($_POST['postJob'])){
$obj = new CreateJob();
$jobCategory = $_POST['jobCategory'];
$jobDescription = $_POST['jobDescription'];
$jobHeadline = $_POST['jobHeadline'];
$jobLocation = $_POST['jobLocation'];
$newJob = $obj->uploadJob($jobCategory, $jobDescription, $jobHeadline, $jobLocation);
}
Everything works fine, however this code feels to procedural for me, and I feel I am missing some OOP concepts...?
Specifically is my method uploadJob()
inside the CreateJob{}
class correct or should I change some aspects of it?
Any other help / advice appreciate. Please keep in mind im a rookie!
EDIT:
Here is part of my table jobs
, should anybody want to view it when attempting to answer the question