我有一个用 PHP 编写的表单。用户填写的表单数据直接保存到 MySQL 数据库中,图像和下拉选项除外。
我的问题是:
- 将图像或其路径保存到数据库中
- 检索那些图像
- 将下拉选项保存到数据库中
这是表单的 HTML 代码:(form.html)
<!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=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
var categories = [];
categories["startList"] = ["Rental","Sale"]
categories["Rental"] = ["Residential","Commercial"];
categories["Sale"] = ["Commercial","Residential"];
categories["Residential"] = ["Flot","Independent"];
categories["Commercial"] = ["Play & Plug","Baseshare"];
categories["Biography"] = ["Play & Plug","Bareshare"];
categories["Fiction"] = ["Flot","Independent"];
var nLists = 3; // number of select lists in the set
function fillSelect(currCat, currList) {
var step = Number(currList.name.replace(/\D/g,""));
for (i = step; i < nLists+1; i++) {
document.forms['tripleplay']['List'+i].length = 1;
document.forms['tripleplay']['List'+i].selectedIndex = 0;
}
var nCat = categories[currCat];
for (each in nCat) {
var nOption = document.createElement('option');
var nData = document.createTextNode(nCat[each]);
nOption.setAttribute('value',nCat[each]);
nOption.appendChild(nData);
currList.appendChild(nOption);
}
}
function init() {
fillSelect('startList',document.forms['tripleplay']['List1'])
}
navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', init, false) : addEventListener('load', init, false);
</script>
</head>
<body>
<table width="60%">
<form action="process.php" method="post" enctype="multipart/form-data" name="tripleplay">
<tr>
<td width="44%">Full Name : </td>
<td width="56%"><input size="25" type="text" name="fullname" id="fullname" /></td>
</tr>
<tr>
<td valign="top">Rental Type:</td>
<td>
<select name = 'List1' onchange = "fillSelect(this.value,this.form['List2'])">
<option selected>Make a Selection</option>
</select>
<br /><br />
<select name = 'List2' onchange = "fillSelect(this.value,this.form['List3'])">
<option selected>Make a Selection</option>
</select>
<br /><br />
<select name = 'List3' onchange = "getValue(this.value, this.form['List2'].value, this.form['List1'].value)">
<option selected >Make a Selection</option>
</select>
</td>
</tr>
<tr>
<td>Area : </td>
<td><input size="25" type="text" name="area" id="area" /> sq.ft.</td>
</tr>
<tr>
<td>Owner Mobile / Landline</td>
<td><input size="25" type="text" name="ownermobile" id="ownermobile" /></td>
</tr>
<tr>
<td><p>E-mail</p></td>
<td><input size="25" type="text" name="email" id="email" /></td>
</tr>
<tr>
<td valign="top">Pictures of Property</td>
<td>
<input type="file" name="image_one" id="image_one" />
<input type="file" name="image_two" id="image_two" />
<input type="file" name="image_three" id="image_three" />
</td>
</tr>
<tr>
<td valign="top">Other details you would like to share about your property:</td>
<td>
<textarea size="25" name="otherdetail" id="otherdetail" cols="45" rows="5">
</textarea>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr>
</form>
</table>
</body>
</html>
我的流程表单看起来像这样(process.php)
<?
if( $_POST )
{
$con = mysql_connect("","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("", $con);
$users_fullname = $_POST['fullname'];
$users_area = $_POST['area'];
$users_ownermobile = $_POST['ownermobile'];
$users_email = $_POST['email'];
$users_image_one = $_POST['image_one'];
$users_image_two = $_POST['image_two'];
$users_image_three = $_POST['image_three'];
$users_otherdetail = $_POST['otherdetail'];
$users_fullname = htmlspecialchars($users_fullname);
$users_area = htmlspecialchars($users_area);
$users_ownermobile = htmlspecialchars($users_ownermobile);
$users_email = htmlspecialchars($users_email);
$users_image_one = htmlspecialchars($users_image_one);
$users_image_two = htmlspecialchars($users_image_two);
$users_image_three = htmlspecialchars($users_image_three);
$users_otherdetail = htmlspecialchars($users_otherdetail);
$query = "
INSERT INTO `vkrental`.`Owner_detail` (
`fullname` ,
`area` ,
`ownermobile` ,
`email` ,
`image_one` ,
`image_two` ,
`image_three` ,
`otherdetail`
)
VALUES ( '$users_fullname',
'$users_area', '$users_ownermobile', '$users_email', '$users_image_one','$users_image_two','$users_image_three', '$users_otherdetail'
);";
mysql_query($query);
echo "<h2>some text.</h2>";
mysql_close($con);
}
?>
和 mysql 数据库表看起来像这样
CREATE TABLE `Owner_detail` (
`id` int(10) NOT NULL auto_increment,
`fullname` varchar(30) NOT NULL,
`area` varchar(30) NOT NULL,
`ownermobile` varchar(20) NOT NULL,
`email` varchar(20) NOT NULL,
`image_one` blob NOT NULL,
`image_two` blob NOT NULL,
`image_three` blob NOT NULL,
`otherdetail` varchar(300) NOT NULL,
PRIMARY KEY (`id`)
);
请帮助我。