0

首先形式有效。

目前我有一个上传表单,上面有大约 10 个字段。该表单在插入任何文本输入时可以正常工作,但是当我从下面的下拉列表之一中选择一个选项时,它只会将一个空白字段插入数据库。

我真的不明白为什么要这样做,但是有人的贡献会很棒,因为我已经有几天了这个问题了。

我的问题是:如何在下拉列表中选择选项以插入数据库字段?

请参阅以下文件:

上传.html

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>test file upload</title>
<link rel="stylesheet" type="text/css" href="css/master.css"/>
</head>

<body>

<div id="wrapper">

<div class="uploadForm" align="center">

<form method="post" action="insert.php">

Heading:<br/><input name="heading" class="contentUpload" type="text" /><br/>

Text:<br/><input name="text" type="text"/><br/>

Frendly URL :<br/><input name="frendlyUrl" class="contentUpload" type="text" /><br/>

Location:<br/><select type="text" name="location" id="location">
                    <option value="Aberdeen">Aberdeen</option>
                    <option value="Aberdeenshire">Aberdeenshire</option>
                    <option value="Angus">Angus</option>
                    <option value="Argyll And Bute">Argyll &Aacute; Bute</option>
                    <option value="Clackmannanshire">Clackmannanshire</option>
                    <option value="Dumfries And Galloway">Dumfries &Aacute; Galloway</option>
                    <option value="Dundee">Dundee</option>
                    <option value="East Ayrshire">East Ayrshire</option>
                    <option value="East Dunbartonshire">East Dunbartonshire</option>
                    <option value="East Lothian">East Lothian</option>
                    <option value="East Renfrewshire">East Renfrewshire</option>
                    <option value="Edinburgh">Edinburgh</option>
                    <option value="Eilean Siar">Eilean Siar</option>
                    <option value="Falkirk">Falkirk</option>
                    <option value="Fife">Fife</option>
                    <option value="Glasgow">Glasgow</option>
                    <option value="Highlands">Highlands</option>
                    <option value="Inverclyde">Inverclyde</option>
                    <option value="Midlothian">Midlothian</option>
                    <option value="Moray">Moray</option>
                    <option value="North Ayrshire">North Ayrshire</option>
                    <option value="North Lanarkshire">North Lanarkshire</option>
                    <option value="Orkney">Orkney</option>
                    <option value="Perth And Kinross">Perth &Aacute; Kinross</option>
                    <option value="Renfrewshire">Renfrewshire</option>
                    <option value="Scottish Borders">Scottish Borders</option>
                    <option value="Shetland Islands">Shetland Islands</option>
                    <option value="South Ayrshire">South Ayrshire</option>
                    <option value="South Lanarkshire">South Lanarkshire</option>
                    <option value="Stirling">Stirling</option>
                    <option value="West Dunbartonshire">West Dunbartonshire</option>
                    <option value="West Lothian">West Lothian</option>
            </select>
<br/>

Age:<br/><input name="age" class="contentUpload" type="text" /><br/>

URL:<br/><input name="url" class="contentUpload" type="text" /><br/>

Image Name (example: abc.png):<br/><input name="imageName" class="contentUpload" type="text" /><br/>

Category:<br/><select type="text" name="category" id="category">
                    <option value="Financial">Financial</option>
                    <option value="Business And Administration">Business &Aacute; Administration</option>
                    <option value="Care">Care</option>
                    <option value="Construction">Construction</option>
                    <option value="Creative">Creative</option>
                    <option value="Energy">Energy</option>
                    <option value="Engineering">Engineering</option>
                    <option value="Food And Drink">Food &Aacute; Drink</option>
                    <option value="Hair And Beauty">Hair &Aacute; Beauty</option>
                    <option value="Hospitality">Hospitality</option>
                    <option value="IT">IT</option>
                    <option value="Landbased">Landbased</option>
                    <option value="Motor And Transport">Motor &Aacute; Transport</option>
                    <option value="Retail">Retail</option>
                    <option value="Scientific">Scientific</option>
                    <option value="Sport And Leisure">Sport &Aacute; Leisure</option>
                    <option value="Enterprise">Enterprise</option>
            </select>
<br/>

Type:<br/><input name="type" class="contentUpload" type="text" /><br/>

<input name="Submit" type="submit" value="submit" />

</form>

</div>

</div>

</body>

</html>

插入.php

<?php
$con = mysql_connect("x","x","x");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("x", $con);

$sql="INSERT INTO podContent (url, heading, text, age, location, imageName, category, type, friendlyUrl)
VALUES
('$_POST[url]','$_POST[heading]','$_POST[text]','$_POST[age]','$_POST[location]','$_POST[imageName]','$_POST[category]','$_POST[type]','$_POST[friendlyUrl]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con);
?>

提前谢谢了。

4

1 回答 1

0

尝试从您的选择标签中删除 type="text" 。

它不是一个有效的属性。

http://www.w3schools.com/tags/tag_select.asp

还要检查以确保您的数据库字段能够处理值的长度。

于 2013-02-17T17:07:23.910 回答