如果存在相同的 question_text
但 first_word 不存在,如何不插入值。
示例(question_text
是整个句子,第一个单词是句子中的第一个单词
。)
他疯了。//插入
他很聪明。//插入
他很聪明。//存在不插入
$first_word = current(explode(' ', $_POST['question_text']));
mysql_query("INSERT INTO questions (question_id,question_text,field_name)
VALUES ('','$_POST[question_text]','$first_word')");
最佳答案
您可以运行此 SQL once 查询以防止具有相同内容的重复条目:
ALTER TABLE questions ADD UNIQUE(question_text);
关于php - 如果已经存在则不要插入条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5421267/