私はmysqlでphpを使用しています。
さまざまなフィールドを持つフォームを作成したい。
htmlでのフォームはこんな感じです。
<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);
function MM_validateForm() { //v4.0
if (document.getElementById){
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
} }
</script>
</head>
<body>
<table width="60%"><form action="process.php" method="post" enctype="multipart/form-data" name="tripleplay" onsubmit="MM_validateForm('fullname','','R','area','','R','ownermobile','','RisNum','email' ,'','RisEmail','otherdetail','','R');return document.MM_returnValue">
<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' id="List1" onchange="fillSelect(this.value,this.form['List2'])">
<option selected>Make a Selection</option>
</select>
<br /><br />
<select name='List2' id="List2" onchange="fillSelect(this.value,this.form['List3'])">
<option selected>Make a Selection</option>
</select><br /><br />
<select name='List3' id="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>
そして私のフォーム処理ファイルはこのようになっています。
<?
if( $_POST )
{
$con = mysql_connect("","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("vkrental", $con);
$users_fullname = $_POST['fullname'];
$users_area = $_POST['area'];
$users_List1 = $_POST['List1'];
$users_List2 = $_POST['List2'];
$users_List3 = $_POST['List3'];
$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_List1 = htmlspecialchars($users_List1);
$users_List2 = htmlspecialchars($users_List2);
$users_List3 = htmlspecialchars($users_List3);
$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` ,
`List1` ,
`List2` ,
`List3` ,
`ownermobile` ,
`email` ,
`image_one` ,
`image_two` ,
`image_three` ,
`otherdetail`
)
VALUES ( '$users_fullname',
'$users_area', '$users_List1','$users_List2','$users_List3', '$users_ownermobile', '$users_email', '$users_image_one','$users_image_two','$users_image_three', '$users_otherdetail'
);";
mysql_query($query);
echo "<h2>.</h2>";
mysql_close($con);
}
?>
そしてmysqlテーブルはこのようになっています
CREATE TABLE `Owner_detail` (
`id` int(10) NOT NULL auto_increment,
`fullname` varchar(30) NOT NULL,
`List1` varchar(20) NOT NULL,
`List2` varchar(20) NOT NULL,
`List3` varchar(20) 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`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=24 ;
私の問題は、1) mysql テーブルで画像が [BLOB - 0 B] を示していますが、この画像を phpmyadmin と Web ブラウザーで表示する必要がありますか? 2) phpmyadmin(localhost) では、カーソルが動いているときはいつでも下線が表示されますが、Web ホストでは表示されません。なぜこれ?
どんな助けでも素晴らしいです。