I am trying to display every job record in my database and when a user clicks on a record, it will go on to display the job description for that record on a new page.
At my current state I've managed to display every job, clicking on them will direct the user to the "showjob.php?id=". My problem is that it isn't displaying information for my job.
Page with list of jobs: THIS WORKS
$results = $pdo->query('SELECT * FROM jobs');
foreach ($results as $row) {
echo '<a class="job_listing_href" href="showjob.php?id="' . $row['job_id'] . '><div id="job_listing">' . $row['job_title'] . ' '
. $row['cat_job'] . '</div><br/><br/>';
}
Page with individual job information:
$pkey = mysql_real_escape_string($_GET['job_id']);
$sql = "SELECT * FROM jobs WHERE job_id='$pkey'";
foreach ($results as $pdo) {
echo '<div id="job_listing">' . $row['job_title'] . ' ' . $row['cat_job'] . '</div><div id="job_listing_content">' . $row['job_desc'] .
'</div>';
}
It isn't related to my job_desc as I can implement it to my previous page and it lists it just fine. My guess is that it's something to do with my $_GET but not sure.
Also as a sidenote, I'm aware my website is vulnerable to SQL injection, I'm going to fix it soon :) Can anyone provide a solution or put me on the right tracks?
Thank you to anyone spending the time helping me!
UPDATE
I have took everyone's suggestions - thank you, but my "showjob" page still isn't displaying anything. This is my new code:
$pkey = mysql_real_escape_string($_GET['id']);
$sql = "SELECT * FROM jobs WHERE job_id='$pkey'";
$results = $pdo->query($sql);
foreach($results as $row) {
echo '<div id="job_listing">' . $row['job_title'] . ' ' . $row['cat_job'] . '</div><div id="job_listing_content">' . $row['job_desc'] .
'</div>';
}
$results = $pdo->query($sql);and theforeachshould loop$results as $rowmysql_with PDO here and at the same time? and which MySQL API are you using to connect with?mysql_real_escape_stringis amysql_function and you're connecting with PDO. No love. every answers below are wrong so far. Look at my link I left you above. The question may get closed because of it.