I'm developing a mobile application for android and I'm trying to compare a variable on the phone to a variable already in the database, so that I can insert it if it's new and update it if it already exists.
$name_check = $_POST['Name'];
$result = mysqli_query($con, "SELECT * FROM Data WHERE Name = $name_check");
if($result && mysqli_num_rows($result) > 0)
{
// Update entry
}
This code doesn't seem to work as this block is skipped over and goes to my else block where a new entry is written, so I end up with loads of entries instead of updating one.
I have another field in the table called "Level", and when I compare against that it seems to work, which just confuses me further.
If anyone has any insight into how to do this or why it's not working for me I'd be very grateful.