开发者

Value still inserting, even though query encased in if statement which should stop it from doing so?

I really don't know what's going on here, I've been racking my brain for ages trying to figu开发者_JAVA技巧re this out;

I have the variable $overflow = $_POST['overflow']; and then the following code:

if($overflow != "" || $overflow != "Overflow link"){
    $query = "DELETE FROM links WHERE overflow='YES'";
    $result = mysql_query($query) or die(mysql_error());
    $query = "INSERT INTO links (link, overflow) VALUES ('$overflow','YES') ON DUPLICATE KEY UPDATE overflow=VALUES(overflow)";
    $result = mysql_query($query) or die(mysql_error());
}

The idea is if $overflow is empty or holds the default value, it isn't inserted, but if it's a valid value the already existing entry for it is deleted (because I can't make the column unique), and it's re-inserted.

Anyone have any idea was to why it's inserting on ANY value?

Any help would be greatly appreciated!


"If not empty or not some value".

Well, it cannot be empty and "some value" at the same time, so this condition is always true. You're looking for:

if ($overflow != "" && $overflow != "Overflow link")


if(!empty($overflow) && $overflow != "Overflow link"){
    $query = "DELETE FROM links WHERE overflow='YES'";
    $result = mysql_query($query) or die(mysql_error());
    $query = "INSERT INTO links (link, overflow) VALUES ('$overflow','YES') ON DUPLICATE KEY UPDATE overflow=VALUES(overflow)";
    $result = mysql_query($query) or die(mysql_error());
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜