Infinitewin
Infinitewin

Reputation: 1

Explain this SQL code in PHP script

I found this piece of code from an answer on Several drop down list input to one field table. It really seems like something I can use in my current project. The current project is about populating a table with two dropdown boxes (which are populated themselves with tables). However, I don't understand what personal changes I need to do in order to make it work. attributes? :attributes? Can someone make sense of it?

  $levels = $_POST['level1'][0].",".$_POST['level1'][1];

  //Now you have a string called $levels
  // Which contains a comma seperated list, to insert into db / one field

  //Insert into your table...change your table and field names to real values...

  $sql = "INSERT INTO yourTable (attributes) VALUES (:attributes)";
  $q = $db->prepare($sql);
  $q->execute(array(':attributes'=>$levels));
  ?>

Upvotes: 0

Views: 96

Answers (1)

Rob Agar
Rob Agar

Reputation: 12447

:attributes is a bound parameter in a PHP prepared statement which inserts a row into a table with an attributes field, setting just that field.

Upvotes: 1

Related Questions