Hey guys I'm builing some php pages and I've run into a snag. I have a page that lets an admin of the site view entries in the database and then if they click on the edit button it takes them to another page that populates a form with the correct information for them to now edit. My question is I want the admin to either insert a new row in the database (if they happen to change the date of the data) or just update the data (if they change anything but the date). so my php looks something like this:
CODE
//store the original date
$orig_date = $_GET['Date']; //Where the date is being passed through the URL from the previous page
//now process the form
if((isset($_POST['MM_insert'])) && ($_POST['MM_insert'] == "Edit_Topic"))
{
//store the data from the form fields
global $orig_date;
$topic_title = htmlentities($_POST['topic_title'], ENT_QUOTES);
$topic_date = htmlentities($_POST['topic_date'], ENT_QUOTES);
$topic_description = htmlentities($_POST['topic_description'], ENT_QUOTES);
$topic_image1 = htmlentities($_POST['topic_image1'], ENT_QUOTES);
$topic_alttag = htmlentities($_POST['topic_alttag1'], ENT_QUOTES);
$topic_image2 = htmlentities($_POST['topic_image2'], ENT_QUOTES);
$topic_alttag2 = htmlentities($_POST['topic_alttag2'], ENT_QUOTES);
$topic_sound_file = htmlentities($_POST['topic_sound_file'], ENT_QUOTES);
$topic_video_file = htmlentities($_POST['topic_video_file'], ENT_QUOTES);
//Create a SQL statement
if($orig_date != $topic_date)
{
$topic_query = "INSERT INTO topic (Title, Date, Description, Image, AltTag, Image2, AltTag2, SoundFile, VideoFile) VALUES ('$topic_title', '$topic_date', '$topic_description', '$topic_image1', '$topic_alttag', '$topic_image2', '$topic_alttag2', '$topic_sound_file', '$topic_video_file')";
}
else
if($orig_date == $topic_date)
{
$topic_query = "UPDATE topic SET Title = '$topic_title', Date = '$topic_date', Description = '$topic_description', Image = '$topic_image1', AltTag = '$topic_alttag', Image2 = '$topic_image2', AltTag2 = '$topic_alttag2', SoundFile = '$topic_sound_file', VideoFile = '$topic_video_file' WHERE Date = '$orig_date'";
}
//select the database and execute SQL query
mysql_select_db($database_uBeatConn);
$topic_result = mysql_query($topic_query) or die(mysql_error());
}
so my problem seems to be that $orig_date is not keeping it's value throughout the life of the if statement and therefore my code will always create a new row in the database instead of updating when necessary. Any light that can be shed on this will be much appreciated. As stated above the date of the topic to update is passed through the URL from the page where the database entries are viewed.