There are many tutorials out there but i haven't been able to make it work somehow.
I am trying to update my table if data in all but except on column matches the data i'm inserting through a form. I am using php as the scripting language and mysql at the backend.
$name = $_POST['name'];
$phone = $_POST['phone'];
$genders = $_POST['gender'];
$hno = $_POST['hno'];
$sector = $_POST['sector'];
$city = $_POST['city'];
$state = $_POST['state'];
$pin = $_POST['pin'];
$ailt = $_POST['ailt'];
$q="INSERT INTO manage (name, phone, gender, hno, sector, city, state, pin, ailt)
VALUES ('$name', '$phone', '$genders', '$hno', '$sector','$city','$state','$pin','$ailt')
ON DUPLICATE KEY UPDATE ailt='$ailt'";
What I'm trying to do is insert the data if it doesn't already exists, or if all the fields except ailt
match, update that row with the new ailt
.
I have been stuck on this for a couple of hours. Looks simple, but i just can't get it to work, as the rows keep inserting. They don't update, even when I keep all the data same and put a different value for ailt.