2012-03-10 7 views
0

데이터베이스에 선택 옵션을 포함시킬 가능성을 찾고 있습니다. 어떤 이유로 sound_upload.php의 POST 함수에 값이 표시되지 않습니다. 나는 항상 "카테고리가 null 일 수 없다"는 mysql 메시지를 얻는다. 이 문제는 jascript의 사용과 관련이 있습니까? 아니면 단순히 잘못된 PHP 코드를 사용 했습니까?PHP에서 선택 옵션 요청

upload.php로

<?php 
    require_once('auth.php'); 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>My Profile</title> 
<link href="loginmodule.css" rel="stylesheet" type="text/css" /> 
<script type="text/javascript" src="./../../src/jquery-1.6.1.min.js"></script> 
<script type="text/javascript" src="./../../src/jquery.relatedselects.min.js"></script> 

<script type="text/javascript"> 
$(function(){ 

    $("#categories").relatedSelects({ 
     onChangeLoad: 'datasupplier.php', 
     selects: ['categoryID', 'subcategoryID'] 
    }); 

}); 
</script> 

</head> 
<body> 
<h1>Upload</h1> 
<a href="profile.php">My Profile</a> | <a href="upload.php">Upload</a> | <a href="http://www.soundypedia.com/index.php">Logout</a> 
<p> 
<form action="sound_upload.php" method="post" id="categories" enctype="multipart/form-data"> 
     <table align="center"> 
       <tr valign="baseline"> 
         <td nowrap="nowrap" align="right">Title: </td> 
         <td><input type="text" name="title" value="" size="32" /></td> 
       </tr> 

        <tr valign="baseline"> 
          <td nowrap="nowrap" align="right">Category: </td> 
          <td> 
           <select name="categoryID"> 
            <option value="">Category</option> 
            <option value="Natural">Natural</option> 
            <option value="Urban">Urban</option> 
            <option value="Musical">Musical</option> 
            <option value="Abstract">Abstract</option> 
            <option value="Signals">Signals</option> 
           </select> 
          </td> 
        </tr> 
        <tr valign="baseline"> 
          <td nowrap="nowrap" align="right">Subcategory: </td> 
          <td> 
           <select name="subcategoryID"> 
            <option value="">Subcategory</option> 
           </select> 
          </td> 
        </tr> 

       <tr valign="baseline"> 
         <td nowrap="nowrap" align="right">Keywords: </td> 
         <td><input type="text" name="keywords" value="" size="32" /></td> 
       </tr> 
       <tr valign="baseline"> 
         <td nowrap="nowrap" align="right">Upload: </td> 
         <td><label> 
         <input type="file" name="upload" id="upload" /> 
         <?php // Configuration - Your Options 
          $allowed_filetypes = array('.mp3','.mid','.m4a'); // These will be the types of file that will pass the valartistation. 
          $max_filesize = 5242880; // Maximum filesize in BYTES (currently 5.0 MB). 
          $upload_path = './../../sounds/'; // The place the files will be uploaded to (currently a 'files' directory). 
          $filename = $_FILES['upload']['name']; // Get the name of the file (including file extension). 
          $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename. 

           // Upload the file to your specified path. 
          if(move_uploaded_file($_FILES['upload']['tmp_name'],$upload_path . $filename))?> 
         </label></td> 
       </tr> 
       <tr valign="baseline"> 
       <td></td> 
       <td><input type="submit" name="submit" class="submit" /></td> 

     </table> 
     <div id="hide"> 
      <input type="text" name="artist" value="<?php echo $_SESSION['SESS_FIRST_NAME']; echo ' '; echo $_SESSION['SESS_LAST_NAME'];?>"/> 
      <input type="hartistden" name="date" value="<?php echo date("d.m.Y"); ?>" /> 
      <input type="hartistden" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" /> 
     </div> 

</form> 
</p> 
</body> 
</html> 

sound_upload.php

<?php require_once('sound_database.php'); ?> 
<?php 
if (!function_exists("GetSQLValueString")) { 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{ 
    if (PHP_VERSION < 6) { 
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
    } 

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 

    switch ($theType) { 
    case "text": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break;  
    case "long": 
    case "text": 
     $theValue = ($theValue != "") ? textval($theValue) : "NULL"; 
     break; 
    case "double": 
     $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; 
     break; 
    } 
    return $theValue; 
} 
} 

$editFormAction = $_SERVER['PHP_SELF']; 
if (isset($_SERVER['QUERY_STRING'])) { 
    $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); 
} 

if (isset($_POST["submit"])) { 
    $insertSQL = sprintf("INSERT INTO sounds (id, title, artist, category, subcategory, keywords, upload, download, rating, ip, date) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", 
         GetSQLValueString($_POST['id'], "text"), 
         GetSQLValueString($_POST['title'], "text"), 
         GetSQLValueString($_POST['artist'], "text"), 
         GetSQLValueString($_POST['category'], "text"), 
         GetSQLValueString($_POST['subcategory'], "text"), 
         GetSQLValueString($_POST['keywords'], "text"), 
         GetSQLValueString($_FILES['upload']['name'], "text"), 
         GetSQLValueString($_POST['download'], "text"), 
         GetSQLValueString($_POST['rating'], "text"), 
         GetSQLValueString($_POST['ip'], "text"), 
         GetSQLValueString($_POST['date'], "text")); 

    mysql_select_db($database_test, $test); 
    $Result1 = mysql_query($insertSQL, $test) or die(mysql_error()); 
} 
?> 
<?php 
$Anzahl = mysql_affected_rows(); 
    if ($Anzahl>0) 
    { 
     echo 'Your sound upload has been successful!<br>To go back click <a href="upload.php">here</a>'; 
    } 
    else 
    { 
     echo 'An error has occured! Your upload has not been saved.<br>To go back click <a href="upload.php">here</a>'; 
    } 
?> 
<link href="loginmodule.css" rel="stylesheet" type="text/css" /> 

답변

1

categoryID하지 category을 게시 귀하의 선택 상자처럼 보인다.

<select name="categoryID"> 
    ... 
</select> 

업데이트 서버 측 코드를 따라 당신은 황금해야한다 :

GetSQLValueString($_POST['categoryID'], "text"), 
+0

덕분에 어떤 바보 같은 실수! –

+0

걱정 마세요, 친구! 기꺼이 도와주세요. – rjz