0

I have the following code and the plan is to display the data from the database but allow for the administrator of the site to delete a row if a job is no longer available. I have put "Delete" where I would like a link to delete the row.I have tried using <a href='delete1.php?del=$row[JobID]'>Delete</a> but that just throws an error up on the page.

<?php
include_once('db.php');

$result = mysqli_query($con,"SELECT * FROM Job ORDER BY JobID");

echo "<table border='1'>
      <tr>
          <th>Job ID</th>
          <th>Job Title</th>
          <th>Job Description</th>
          <th>Industry</th>
          <th>Job Type</th>
          <th>Salary</th>
          <th>County</th>
          <th>Town</th>
          <th>Delete</th>
     </tr>";

while($row = mysqli_fetch_array($result))
{
    echo "<tr>";
    echo "<td>" . $row['JobID'] . "</td>";
    echo "<td>" . $row['JobTitle'] . "</td>";
    echo "<td>" . $row['JobDescription'] . "</td>";
    echo "<td>" . $row['Industry'] . "</td>";
    echo "<td>" . $row['JobType'] . "</td>";
    echo "<td>" . $row['Salary'] . "</td>";
    echo "<td>" . $row['County'] . "</td>";
    echo "<td>" . $row['Town'] . "</td>";
    echo "<td>" . "Delete" . "</td>";
    echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>
7
  • shouldnt it be <a href="delete1.php?del=$row[\'JobID\']">Delete</a> Commented Apr 12, 2013 at 14:31
  • @JohnConde Those look like mysqli_ functions to me. The title is misleading. Commented Apr 12, 2013 at 14:31
  • 1
    1) What error? 2) How does delete1.php look like? Commented Apr 12, 2013 at 14:31
  • provide the code of delete.php Commented Apr 12, 2013 at 14:32
  • @dreamweiver why would you escape the ' symbols inside the " string? Commented Apr 12, 2013 at 14:36

1 Answer 1

1

You should put this in the the listing code:

 echo "<a href='delete1.php?del={$row['JobID']}'>Delete</a>";

(documentation)

Then, in your delete1.php you should have something like:

$jobid = intval($_GET['JobID']);
if ($jobid > 0) {
     mysqli_query($con, "DELETE FROM Job WHERE JobID=$jobid LIMIT 1");
}

(note: this is untested and can be quite insecure; it only shows the concept on how to do this)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.