2013-09-16 39 views
0

正如你可以在下面的PHP代码中看到的,我将从数据库表中获取组合框的值。它显示表中的所有列没有任何问题,但是当我想将组合框的值传回表中时,它总是传递值1。为什么?为什么combobox每次都会传递一个值?

<?php 
$leccom = mysql_query("select Lec_ID, Lec_Name from lecturer") or die(mysql_error()); 

while ($result = mysql_fetch_array($leccom)) { 
    $name = $result[Lec_Name]; 
    $id_leccom = $result[Lec_ID]; 
    echo "<option value='$id_leccom'> $name</option>"; 
} 

?> 

下一个文件:

<?php 
mysql_select_db('lms', mysql_connect('localhost', 'root', '')) or die(mysql_error()); 

// Function to sanitize values received from the form. Prevents SQL injection 
function clean($str) { 
    $str = @trim($str); 
    if (get_magic_quotes_gpc()) { 
     $str = stripslashes($str); 
    } 

    return mysql_real_escape_string($str); 
} 

// Sanitize the POST values 

$filedesc = clean($_POST['pdesc']); 
$fname = clean($_POST['Pre_Name']); 
$com = clean($_post[$id_Leccom]); 
echo $_post['comselection']; 

// $subject= clean($_POST['upname']); 
// upload random name/number 

$rd2 = mt_rand(1000, 9999) . "_File"; 

// Check that we have a file 

if ((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) 
{ 

    // Check if the file is JPEG image and it's size is less than 350Kb 

    $filename = basename($_FILES['uploaded_file']['name']); 
    $ext = substr($filename, strrpos($filename, '.') + 1); 
    if (($ext != "exe") && ($_FILES["uploaded_file"]["type"] != "application/x-msdownload")) 
    { 

     // Determine the path to which we want to save this file 
     // $newname = dirname(__FILE__).'/upload/'.$filename; 

     $newname = "uploads/" . $rd2 . "-" . $filename; 

     // Check if the file with the same name is already exists on the server 
     // Attempt to move the uploaded file to it's new place 

     if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $newname))) 
     { 

      // successful upload 
      // echo "It's done! The file has been saved as: ".$newname; 
      // echo "$filedesc,$newname,$fname,$comlec"; 

      mysql_query("INSERT INTO `lms`.`presentation` (`Pre_Name` ,`Path` ,`PLec_ID` ,`pdatein` ,`pdesc`) values ('$fname','$newname','1',NOW(),'$filedesc')") or die("failed"); 

      // mysql_query("INSERT INTO presentation (pdesc,path,pdatein,Pre_Name,plec_id) VALUES ('$filedesc','$newname',NOW(),'$fname','$comlec')") or die("query failed"); 
      // mysql_query("INSERT INTO presentation ('pdesc','path','Pre_Name','PLec_ID') values ('$filedesc','$newname','$fname','$comlec')") ; 

      header("location: fileupload.php"); 
     } 
    } 
} 

?> 
+1

我们展示完整的代码。 –

回答

0
$name = $result['Lec_Name']; 
    $id_leccom = $result['Lec_ID']; 

echo "<option value='".$id_leccom."'>$name</option>"; 
+0

我试过了,但是我得到的结果与之前一样 – user2784585

+0

@ user2784585尝试更新 –

+0

仍然不能正常工作 – user2784585

相关问题