Reputation: 11
This might be a stupid question but it honestly has me stumped.
I have an existing table which I want to update with new items. However if the old items are altered elsewhere then I want this to update automatically as well.
I have set the $eid as being a unique identifier so the tables wont be duplicated. I use this to add in new items.
mysqli_query($con,"INSERT INTO `notification` (`nid` ,`eid` ,`subject` ,`active` ,`date`)VALUES (NULL , '$eid[$i]', '$subject[$i]', '$active[$i]', '$eventdate[$i]')");
With my second query, I am trying to update the existing tables with the current updated information.
mysqli_query($con,"UPDATE `notification` SET `nid`=NULL,`eid`='$eid[$i]',`subject`='$subject[$i]',`active`='$active[$i]',`date`='$eventdate[$i]' WHERE `active` = 0");
However this second query just doesn't seem to work.
Upvotes: 0
Views: 58
Reputation: 31889
More details on error thrown by the MySQL?
However, if the column nid
is your primary key, it cannot be NULL
.
If you do not want to update it, just skip it in the update query:
mysqli_query($con,"UPDATE `notification` SET `eid`='$eid[$i]',
`subject`='$subject[$i]',`active`='$active[$i]',`date`='$eventdate[$i]'
WHERE `active` = 0");
Upvotes: 1
Reputation: 116
try,
mysqli_query($con,"UPDATE notification SET nid= '',eid='".$eid[$i]."',subject='".$subject[$i]."',active='".$active[$i]."',date='".$eventdate[$i]."' WHERE active = '0'");
Upvotes: 0