0
我正在尋找在數據庫中包含選擇選項的可能性。出於某種原因,該值不會在sound_upload.php的POST函數中顯示。我總是得到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" />
謝謝多麼愚蠢的錯誤! – 2012-03-10 21:01:03
不用擔心,夥計!樂意效勞- – rjz 2012-03-10 21:04:58