I am trying to add data from the search form on the site to the mysql database.

Created a table

CREATE TABLE `dle_search` ( `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, `story` varchar(40) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=cp1251; 

It is added like this. Here $story is the data from the search form.

 $db->query( "INSERT INTO " . PREFIX . "_search (story) values ('$story')" ); 

How to make it was not duplicate. It turns out

 id | story 1 | текст 2 | текст 3 | текст 

According to the idea of id I don’t need it at all, but without it I didn’t work out so that I could delete these fields (1-2-3) separately.

  • On the idea of ​​id, I don’t need it at all. Well, throw this field out of the structure, and create a unique index on the story - duplicates cannot be added stupidly ... - Akina
  • This is not the dle_search CREATE TABLE dle_search ( story varchar (40) NOT NULL AUTO_INCREMENT, PRIMARY KEY ( story )) ENGINE = MyISAM DEFAULT CHARSET = cp1251; - steep
  • one
    Well, what autoincrement for the string ??? delete these two words. - Akina
  • Now it is not duplicated, but an error appears with the same search. Duplicate entry 'text for key' PRIMARY ' - steep
  • one
    Well, why would she not appear? Do an INSERT IGNORE, not just an INSERT. - Akina

0