Page 206 - PHP Novice to Ninja

Hello to everyone again.

I don’t understand this line:

$sql = 'DELETE FROM jokecategory WHERE categoryid = :id';

These the complete code:

    // Delete joke associations with this category
try
{
  $sql = 'DELETE FROM jokecategory WHERE categoryid = :id';
  $s = $pdo->prepare($sql);
  $s->bindValue(':id', $_POST['id']);
  $s->execute();
}
catch (PDOException $e)
{
  $error = 'Error removing jokes from category.';
  include 'error.html.php';
  exit();
}

Thank you

What exactly can’t you understand?
This line creates a variable containing SQL query for the database.
The query asks database to delete one row from jokecategory table

I don’t understand where the query take the id.

In the joke category table I have jokeid e categoryid…

Combining those two lines, are you still confused?

Yes, but :id is the id of the category table?

It’s the ID of the category, yes, as indicated by “categoryid” being the field name matched. The SQL is removing entries from the jokecategory table where the categoryid is whatever is specified.

Ok thank you.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.