I am trying to figure out how to take multiple word input in a single text box in a form with each word separated by comma(,) and then paring the word based on comma and inserti
You could do it with PDO too:
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC);
} catch (PDOException $e) {
die('Cannot connect to mySQL server. Details:'.$e->getMessage());
}
if ($_SERVER['REQUEST_METHOD']=='POST' && !empty($_POST['words'])) {
$sql = "INSERT INTO words_table (word) VALUES (:word)";
$stmt = $db->prepare($sql);
$stmt->bindParam(':word', $word);
foreach (explode(',', $_POST['words']) as $word) {
$word = trim($word);
if (empty($word)) {
continue;
}
$stmt->execute();
}
}
//Your form
?>
Words