We help IT Professionals succeed at work.
Get Started

PHP with MySQL Code block error

SeanNij
SeanNij asked
on
445 Views
Last Modified: 2013-11-10
Hi.

I have a php website hosted on Windows Server 2k8 and having a problem with my MySQL class on one page. Not sure if it's my code or something to do with my database query. The problem is my php page shows code instead of the actual variables. (http://www.supportsolutions.co.za/job.php?job_id=482) Here is where my problem lies.


I've supplied my job.class.php and job.php

<?php

class jobs
{ 
	// class variable declarations
	var $mysql;
	var $job_id;
	var $job_position;
	var $job_desc;
	var $job_area;
	var $job_ref;
	var $job_salary;
	var $job_availability;
	var $job_consultant;
	var $job_closing;
	var $job_division;
	var $job_benefits;
	var $job_hrs;
	var $job_bonus;	
	var $job_consultemail;	
	
	// constructor
	function jobs() {
		global $mysql;		
		$this->mysql =& $mysql;
	}
	
	// Populate User Details from either user_name or user_id
	function populate($job_id=false) {
		if (!$job_id){return;}
		
		$job_array=$this->mysql->select("SELECT * FROM jobs WHERE job_id=".$job_id);
		if ($job_array){ 
			$this->job_id=$job_array[0][0];
			$this->job_position=$job_array[0][1];
			$this->job_desc=$job_array[0][2];	
			$this->job_area=$job_array[0][3];
			$this->job_closing=$job_array[0][4];	
			$this->job_division=$job_array[0][5];	
			$this->job_ref=$job_array[0][6];	
			$this->job_salary=$job_array[0][7];	
			$this->job_availability=$job_array[0][8];	
			$this->job_consultant=$job_array[0][9];	
			$this->job_benefits=$job_array[0][10];
			$this->job_hrs=$job_array[0][11];
			$this->job_bonus=$job_array[0][12];
			$this->job_consultemail=$job_array[0][13];
		}		
	}

	// Basic add, edit, delete functions

	function insert_job($job_id, $job_position, $job_desc, $job_area, $job_closing, $job_division, $job_ref, $job_salary, $job_availability, $job_consultant, $job_benefits, $job_hrs, $job_bonus, $job_consultemail) {
		if (!$job_id){return false;}
		//$job_desc = addslashes($job_desc);
		
		$sql="INSERT INTO jobs (job_id, job_position, job_desc, job_area, job_closing, job_division, job_ref, job_salary, job_availability, job_consultant, job_benefits, job_hrs, job_bonus, job_consultemail) ";
		$sql.= "VALUES ('$job_id', '$job_position', '$job_desc', '$job_area', '$job_closing', '$job_division', '$job_ref', '$job_salary', '$job_availability', '$job_consultant', '$job_benefits', '$job_hrs', '$job_bonus', '$job_consultemail')";
		$insert_array=$this->mysql->select($sql);
		if ($insert_array){return true;}
	}

	function update_job($job_id, $job_position, $job_desc, $job_area, $job_closing, $job_division, $job_ref, $job_salary, $job_availability, $job_consultant, $job_benefits, $job_hrs, $job_bonus, $job_consultemail) {
		if (!$job_id){return false;}
		//$job_desc = addslashes($job_desc);
		
		$sql= "UPDATE jobs SET 
		job_id=$job_id, 
		job_position='$job_position', 
		job_desc='$job_desc', 
		job_area='$job_area', 	
		job_closing='$job_closing', 
		job_division='$job_division',
		job_ref='$job_ref',
		job_salary='$job_salary',
		job_availability='$job_availability',
		job_consultant='$job_consultant',
		job_benefits='$job_benefits',
		job_hrs='$job_hrs',
		job_bonus='$job_bonus',
		job_consultemail='$job_consultemail'
		WHERE ";
		$sql.="job_id=$job_id";		
		$update_array=$this->mysql->select($sql);
		if ($update_array){return true;}
	}

	function delete_job($job_id, $permanent=false) {
		if (!$job_id){return false;}
		$sql="DELETE FROM jobs WHERE job_id=$job_id";
		$delete_array=$this->mysql->select($sql);
		return $delete_array;
	}

	// Get jobs	
	function get_jobs($job_id=false) {
		if ($job_id){$specific=" WHERE job_id=$job_id ";
		} else { $specific=""; }
		
		$job_array=$this->mysql->select("SELECT * FROM jobs $specific ORDER BY job_availability DESC, substring(job_ref,5) DESC");
		if ($job_array){ return $job_array; }
	}
	
	function get_jobs_indivision($job_division=false) {
		$job_array=$this->mysql->select("SELECT * FROM jobs WHERE job_division=$job_division ORDER BY job_consultant, substring(job_ref,5) DESC");
		//$job_array=$this->mysql->select("SELECT * FROM jobs WHERE job_availability='Available' ORDER BY job_position");
		if ($job_array){ return $job_array; }
	}	
}
?>

Top of Job.php:
include_once('global9.php'); // Include global class
include_once('jobs.class.php');
$jobs= new jobs();


$job_id=$_GET['job_id'];
$jobs->populate($job_id); //Happens here!!!

?>

Middle of job.php
			<tr>
				<td bgcolor="#800000" width="80px">Position</td>
				<td><?=$jobs->job_position?></td> <!-- AND HERE -->
			</tr>

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
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
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