1
我认为这已经被问到,但没有一个答案对我有意义。我的代码是...检查主键是否存在
if ($current_string == "") {
$new_entry_query = 'INSERT INTO house (id, string) VALUES ("' . $userid . '", "' . $new_home_entry . '")';
mysql_query($new_entry_query);
Header('Location: landing.php?pho=');
} else {
$entry_update_string = $current_string . $new_home_entry;
$new_entry_query = 'UPDATE house SET string="' . $entry_update_string . '" WHERE id="' . $userid . '";';
mysql_query($new_entry_query);
Header('Location: landing.php?pho=');
}
我的表有两列。 “id”是主要的,“string”不是。如果你注意到,在第一个if语句中,当我要求数据库检查我的“id”时,我检查“string”查询是否为空。
我遇到了问题。我的网站上还有另一个功能,从“字符串”列中删除所有内容。如果该函数运行,那么我运行这个脚本,最终会得到一个错误。
我需要检查“id”是否已经存在,以便我知道应该创建一个全新的行,还是只追加“string”。我会怎么做?谢谢。
我为时已晚,要发布同样的事情:)在我看来可能是最好的解决方案。 – Forien 2015-04-02 07:01:43
谢谢。完美的作品。 – Allenph 2015-04-02 07:03:46