Here's what I want to do in three steps.
1-) Get names from the form. Names are being entered into the form using a comma between them.
2-) Get the ID's of the names from the database.
3-) Insert these names into a table.
I hope I made clear what I want to do.
Here's what I've done so far. (I am working with a single page, excluded the form here)
$writer_name = "Franz Kafka, Agatha Christie, George Bernard Shaw"; // I used a
//variable instead of using a form value here
$thing_id = 10;
$values_select = explode(",", $writer_name);
echo $values_select[0]; // returns Franz Kafka, our explode function worked
$who = "SELECT writer_id FROM writer_name WHERE writer_name = '$values_select[]'";
// I stuck here, I need to get all the writer's ID's and store it in an array
// in order to insert below X times (depends on how many writers are entered), right? But how?
$who_result = $sqli->query($who);
$who_row = $who_result->fetch_array();
$who_finish = $who_row['writer_id'];
$values = explode(",", $writer_name);
$control = count($values) - 1;
$new_values = $sqli->prepare("INSERT INTO book(thing_id, person_id) VALUES(?,?)");
for ($i = 0; $i < count($values); $i++) {
if (!empty(trim($values[$i]))) {
$new_values .= "('" . trim($values[$i]) . "')";
}
if ($control == $i) {
$new_values .= ";";
} else $new_values .= ",";
}
$thing->bind_param("ii", $thing_id, $values[$i]); // using integer because I insert data into a junction table that accepts only ID values)
$thing->execute();
... = '$values_select[]'is "impossible" code. You're generating the literal query text... = 'Array[]', which will match nothing.