I am working on a CMS for a basic website. Currently this code below will update the navigation bar correctly, but if you change the position on a subject item, it duplicates position numbers. For instance, if I had the following subject items: Home, About, and Contact - if I wanted to change Contact to position #1, it would...but Home would also stay at position #1.
I am trying to alter this code so that if someone were to update the position of a subject item, the other subject item would switch to the other number. (if Contact changed to position #1, Home would switch to position #3.)
I am not versed in php classes and OOP so basic php coding help would be great. If you need other parts of the code, let me know. Thank you so much.
Code: Select all
$id = mysql_prep($_GET['subj']);
$subject_name = mysql_prep($_POST['subject_name']);
$position = mysql_prep($_POST['position']);
$visible = mysql_prep($_POST['visible']);
$query = "UPDATE subjects SET
subject_name = '{$subject_name}',
position = {$position},
visible = {$visible}
WHERE id = {$id}";
$result = mysql_query($query, $connection);
if (mysql_affected_rows() == 1) {
$message = "The subject was successfully updated.";
} else {
$message = "The subject was NOT updated.";
$message .= "<br />". mysql_error();
}