iluvu9888 0 Newbie Poster

Hi,

I am trying to create a drop down list in php and I want the data to come from a table that I have created in phpmyadmin. The code that I have created allows me to select values from the drop down list and insert the rest of the data. However when I check the the table the SID and Cid are set to 0 and the grade field is empty and the comments field contains the grade. The SID and Cid are both composite keys.

<?php 
        $sql = "SELECT Cid FROM course"; 
        $db1 = new DBStudent_Course(); 
        $db1->openDB(); 
        $result = $db1->getResult($sql); 

        echo"<select name = Cid>"; 
        while ($row = mysql_fetch_object($result)) { 
            echo "<option value = '" . $row->Cid . "'>$row->Cid</option>"; 
        } 

        echo"</select>"; 
        echo "</p>"; 
        ?> 

        <?php 
        $sql = "SELECT SID FROM student"; 
        $db1 = new DBStudent_Course(); 
        $db1->openDB(); 
        $result = $db1->getResult($sql); 

        echo"<select name = SID>"; 
        while ($row = mysql_fetch_object($result)) { 
            echo "<option value = '" . $row->SID . "'>$row->SID</option>"; 
        } 

        echo"</select>"; 
        echo "</p>"; 
        ?> 
        <?php 
        if (!$_POST) { //page loads for the first time 
        ?> 
            <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> 
                grade:<input type="text" name="grade"/><br/> 
                comments:<input type="text" name="comments" /><br /> 
                <input type="submit" value="Save" /> 
            </form> 
<?php 
        } else { 
            $grade = $_POST["grade"]; 
            $comments = $_POST["comments"]; 
            $db1 = new DBStudent_Course(); 
            $db1->openDB(); 
            $numofrows = $db1->insert_student_course("", $SID, $Cid, $grade, $comments); 
            echo "Success. Number of rows affected: 
<strong>{$numofrows}<strong>"; 
            $db1->closeDB(); 
        } 
?>