4
$sql = "INSERT INTO toplist 
       (serverName, serverPassword, serverIp, serverPort, serverBanner,
        serverShortDescription, serverDescription)
       VALUES
       ('$_POST[serverName]', '$_POST[serverPassword]', '$_POST[serverIp]',
        '$_POST[serverPort]', '$_POST[serverBanner]', 
        '$_POST[serverShortDescription]', '$_POST[serverDescription]')";

if (!mysql_query($sql, $con)) {
    die('Error: ' . mysql_error());
}

echo "The server " . $_POST[serverName] . "," . $_POST[serverIp] 
    . " has been added.";

mysql_close($con);

How can I make it so that if the entry "serverIp" does not already exist, it will add it to the database, if it does already exist, then it doesn't do anything. Also, will this be case sensitive too? Will you be able to bypass it bY tYpInG LiKe tHiS?

1
  • 1
    SQL injection attacks are a larger concern than case sensitivity. Commented Feb 21, 2012 at 4:26

1 Answer 1

7

INSERT IGNORE ... will not insert if you have a unique constraint on your column. I would lower case the string before inserting it if you want it to be case insensitive.

http://dev.mysql.com/doc/refman/5.5/en/insert.html

This may also be helpful.

Sign up to request clarification or add additional context in comments.

2 Comments

+1 If he's using MyISAM (which is very common and the most probable), then constraints won't apply in this situation.
I'm having trouble implementing this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.