Editing Rows from Drop Downs
Posted: Wed Sep 23, 2009 9:44 am
Hi there,
I have a course editing script which populates a form with details of courses stored in the database (course tite, description etc) - so that they can be edited and updated.
On element of this is a drop down which displays the chosen category, and allows the user to change this if needs be.
Here's the problem - the menu populates fine, and updates fine if a new category is selected, however, if the category drop down is left untouched - keeping the category as it was, it is removed during the update query.
Here is my code
Firstly the script that displays the category menu...
And the update query...
I have a course editing script which populates a form with details of courses stored in the database (course tite, description etc) - so that they can be edited and updated.
On element of this is a drop down which displays the chosen category, and allows the user to change this if needs be.
Here's the problem - the menu populates fine, and updates fine if a new category is selected, however, if the category drop down is left untouched - keeping the category as it was, it is removed during the update query.
Here is my code
Firstly the script that displays the category menu...
Code: Select all
<?
include("connect.php");
$query="SELECT categoryName FROM category";
$result = mysql_query ($query);
echo "<select name='courseCategory2'><option value=''>{$row['courseCategory2']}</option>";
while($nt=mysql_fetch_array($result)){
echo "<option value='$nt[categoryName]'>$nt[categoryName]</option>";
}
echo "</select>";
?>Code: Select all
<?php
include("connect.php");
if ($_POST['submit'])
{
$courseID = $_POST['courseID'];
$courseTitle = $_POST['courseTitle'];
$courseCategory1 = $_POST["courseCategory1"];
$courseCategory2 = $_POST["courseCategory2"];
$courseCategory3 = $_POST["courseCategory3"];
$courseLinks = $_POST['courseLinks'];
$courseHeader = $_POST['courseHeader'];
$courseOverview = $_POST['courseOverview'];
$courseDuration = $_POST['courseDuration'];
$courseRequirements = $_POST['courseRequirements'];
$courseDescription = $_POST['courseDescription'];
$courseObjectives = $_POST['courseObjectives'];
$courseAgenda = $_POST['courseAgenda'];
$courseTestimonials = $_POST['courseTestimonials'];
$courseDurationtext = $_POST['courseDurationtext'];
$courseVideo = $_POST['courseVideo'];
$str = "UPDATE course SET courseTitle='$courseTitle', courseCategory1='$courseCategory1', courseCategory2='$courseCategory2', courseCategory3='$courseCategory3', courseLinks='$courseLinks', courseHeader='$courseHeader', courseOverview='$courseOverview', courseDuration='$courseDuration', courseRequirements='$courseRequirements', courseDescription='$courseDescription', courseAgenda='$courseAgenda', courseTestimonials='$courseTestimonials', courseDurationtext='$courseDurationtext', courseObjectives='$courseObjectives', courseVideo='$courseVideo' WHERE courseID='$courseID'";
mysql_query($str) or die("Query failed:<br>".mysql_error());
echo "<br><span class='redtitles'>Course Updated Successfully!</span><br><br>";
}
include("connect.php");
$courseID=$_GET['courseID'];
$result=mysql_query("select * from course where courseID='$courseID'");
$row=mysql_fetch_assoc($result);
?>