private void addFriendButton_Click(object sender, EventArgs e) { if (friendsListBox.SelectedIndex == -1) { MessageBox.Show("Please select an Item first!"); } else { int totalFriends = int.Parse(MySQLFunctions.getTotalFriends(email)); string friend = ""; friend = MySQLFunctions.getFriend(email, friendsListBox.Items[friendsListBox.SelectedIndex].ToString()); if (totalFriends == 0) //if user has no friends, just add the friend. { MessageBox.Show("Friend added!"); MySQLFunctions.addFriend(email, friendsListBox.SelectedIndex, friendsListBox.Items[friendsListBox.SelectedIndex].ToString()); } //Search friends table to see if friend is already added. else if (friend == "") { MessageBox.Show("Friend added!"); MySQLFunctions.addFriend(email, friendsListBox.SelectedIndex, friendsListBox.Items[friendsListBox.SelectedIndex].ToString()); } else if (friend == MySQLFunctions.getFriend(email, MySQLFunctions.getName(email))) { MessageBox.Show("You cannot add yourself as a friend!"); } else { MessageBox.Show("Friend is already added!"); } } }