如何从一个输入框中写入多个外部字段


How to write multiple foreign fields from one input box?

我想知道如何使用一个输入列将多个作者添加到一本书中。

例:在网站上,我有输入书籍和输入作者专栏。然后我有"添加"按钮,该按钮检查作者是否已存在,填充多对子表,并在作者和书籍表中添加值(如果它们不存在)。

我的问题是,我如何从一个输入列中添加和检查多个作者,例如在他们之间使用coma或and,以便在必要时检查和添加多个值。

像这样:

Input: Booksname
Input: authorsname authorslastname AND authorsname authorslastname

因此,它会检查并添加书籍和作者表,并写入author_books值。AND 是分隔要检查和/或添加的两个作者值的东西。

检查函数 explode()

你可以使用这样的东西

<?php
$authos = explode(',', $_POST['authors_names'])
foreach ($authors as $author) {
    // do wherever you want with the name of author;
}

如果你知道一点正则表达式,你也可以这样做: