Hello everyone, there is a need to finish tagging the blog. And here's the idea, if the post came ['keywords'], then we break it (separated by commas). Next, we take out the tags from the database, and compare new tags with them, if there are the same ones, then we do nothing, if not, we add the tag name to the database.

Here is the code:

// Допустим это теги которые пришли с $_GET $text = "text1,text2,text3,программирование,text5,text6,text7"; // Разобьём $data = explode(",", $text); // Возьмём теги из БД $sql = mysql_query("SELECT name FROM keywords") or die("Error #345738"); // есть ли они вообще if (mysql_num_rows($sql)) { while ($result = mysql_fetch_assoc($sql)) { // занесём все теги из бд в массив $row[] = $result; } // Переберём массив row foreach ($row as $name) { // переберём входящий массив $_GET foreach ($data as $postname) { // если нет в бд такого массива, занесём его туда if (!$name == $postname) { mysql_query("INSERT INTO keywords (name) VALUES ('" . $postname . "')"); } } } } else { } 

the problem is that nothing happens, in the database there are already a couple of tags.

    1 answer 1

    You can significantly reduce the code using functions such as:
    and their modifications.
    In addition, forget about the mysql_ * family of functions — they will soon disappear from PHP, use PDO .
    And the problem itself is that $name is a string, and $postname is an array, comparing them is an error.