在php中请求一个select选项
Request a select option in php
我正在寻找在数据库中包含select选项的可能性。由于某种原因,这个值没有显示在sound_upload.php的POST函数中。我总是收到mysql消息"category cannot be null"。这个问题是与jascript的使用有关,还是我只是使用了错误的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" />
看起来您的选择框是在发布categoryID
,而不是category
。
<select name="categoryID">
...
</select>
相应地更新你的服务器端代码,你应该是黄金:
GetSQLValueString($_POST['categoryID'], "text"),
相关文章:
- 在php中请求一个select选项
- 更改下一个select元素的类名
- 在js函数调用中嵌入一个select值
- 如何使用angularjs来更改另一个select标记的值
- 你能用javascript设置一个select元素的defaultSelected值吗?
- 根据AngularJS中另一个select元素的值设置选择选项
- 需要一个select标签来跨文档运行javascript
- 使用javascript使用另一个SELECT多个值更新SELECT多个列表(使用erichynds multisele
- 至少选择了一个select-option的表单验证
- 从javascript while循环中创建一个select语句
- 如何使用angular数据绑定将一个复选框绑定到一个select disabled属性
- 如何将两个范围值相加,然后乘以一个select标记
- 如何将值从一个Select更改为另一个Select
- 可以'当第一个select的值改变时,让jquery设置select输入的值
- 在AngularJS中如何根据另一个Select的选择索引来改变一个Select标签的内容
- 如何使用javascript从一个select元素运行多个函数
- 在不使用Select属性的情况下选择一个Select选项(做一个假的鼠标点击)
- 当选择不同的选择选项时,更改另一个SELECT标记的值
- 获取一个select's值,并在angularJs中更改另一个select后将其更新为一个变量
- 动态创建一个select,然后更改ajax调用以附加html