I am very new to SQL and PHP but I want to add a user to a list if an entry does not already exist with their ip. If the entry does exist I just want to update their username.
I can perform both of these operations outside of the "if exists" statement without hiccups but it obviously creates a lot of duplicates. When I wrap it in the "if exists" statement the query stops doing anything.
I know there are a few questions regarding the subject but I have tried following most of the advice, if there is another way to do this I would be happy to consider it, thank you.
<?php
$username = strval($_GET['username']);
$userip = $_SERVER['REMOTE_ADDR'];
$con = mysqli_connect("localhost", "ramendev_jctwood", "M1n1flam3", "ramendev_jctwood") or die ("Failed to connect to MySQL: " . mysqli_connect_error());
mysqli_query($con, "IF EXISTS (SELECT 1 FROM Users WHERE Userip='$userip')
UPDATE Users SET User='$username' WHERE Userip='$userip'
ELSE
INSERT INTO Users (User, Userip) VALUES ('$username', '$userip')
");
?>