Please help me corect my code. I want to insert image into mysql with php but it can't. my code wrote as below:
Table:
CREATE TABLE `TblClothes` (
`ClothesID` int(11) NOT NULL auto_increment,
`ClothesName` varchar(100) NOT NULL,
`Description` varchar(800) NOT NULL,
`Colour` varchar(100) NOT NULL,
`CSize` varchar(100) NOT NULL,
`Price` float NOT NULL,
`Category` varchar(200) NOT NULL,
`Picture` mediumblob NOT NULL,
PRIMARY KEY (`ClothesID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
===========================================================
Upload.htm
<html>
<head>
<title>Test PHP</title>
</head>
<body>
<div id="Layer1" style="position:absolute; width:445px; height:275px; z-index:1; left: 432px; top: 126px; background-color: #CCCCCC; layer-background-color: #CCCCCC; border: 1px none #000000;">
<form enctype="multipart/form-data" action="upload.php" method="post">
<table width="389" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td width="79" height="24"><span class="style7"> Name : </span></td>
<td width="13"><div align="center"><span class="style9">*</span></div></td>
<td width="297" height="24"><input name="form_cname" type="text" id="form_cname" width="150">
</td>
</tr>
<tr>
<td height="24"><span class="style7"> Colour : </span></td>
<td><div align="center"></div></td>
<td height="24"><span class="style15"><input name="form_colour" type="text" width="150">
</span></td>
</tr>
<tr>
<td height="24"><span class="style7"> Size :</span></td>
<td><div align="center"></div></td>
<td height="24"><input name="form_size" type="text" width="150">
</td>
</tr>
<tr>
<td height="24"><span class="style7"> Price :</span></td>
<td><div align="center"><span class="style9">*</span></div></td>
<td height="24"><input name="form_price" type="text" value="0" width="150">
</td>
</tr>
<tr>
<td height="24"><span class="style7"> Category :</span></td>
<td><div align="center"><span class="style9">*</span></div></td>
<td height="24"><select name="form_category">
<option value="Accessories">Accessories</option>
<option value="Casual Day Wear">Casual Day Wear</option>
<option value="Formal Evening Wear">Formal Evening Wear</option>
</select>
</td>
</tr>
<tr>
<td height="24" valign="top"><span class="style7"> Description :</span></td>
<td><div align="center"></div></td>
<td height="24"><textarea name="form_description" cols="40" rows="4"></textarea></td>
</tr>
<tr>
<td height="24"><span class="style7"> Picture :</span></td>
<td><div align="center"><span class="style9">*</span></div></td>
<td height="24"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="form_picture" type="file"></td>
</tr>
<tr valign="bottom">
<td height="30"> </td>
<td height="30" colspan="2"><span class="style9">*</span><span class="style11"> Required to fill up.</span></td>
</tr>
<tr valign="bottom">
<td height="30"> </td>
<td height="30"> </td>
<td height="30"><p>
<input type="submit" value=" Upload ">
</p>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
===========================================================
Upload.php
<?php
$username = "hanum3_admin";
$password = "admin";
$hostname = "localhost";
$cname = $_POST;
$ccolour = $_POST;
$csize = $_POST;
$cprice = $_POST;
$ccategory = $_POST;
$cdescription = $_POST;
//$cpicture = $_POST;
if ($cname ==''){
//$strerror = "Please entry name!";
header ('location: http://www.kambuja-designs.com/uploaderror.php?errortitle=Error!&errormsg=Please entry name!');
}
if ($cprice=="0"){
//$errortitle = "Error!";
//$strerror = "Please entry price bigger than zero!";
header ('location: http://www.kambuja-designs.com/uploaderror.php?errortitle=Error!&errormsg=Please entry price bigger than zero!');
}
if ($ccategory ==''){
//$strerror = "Please select category!";
header ('location: http://www.kambuja-designs.com/uploaderror.php?errortitle=Error!&errormsg=Please select category!');
}
$cname = str_replace("'","''",$cname);
if ($ccolour ==''){
$ccolour = " ";
}
if ($csize ==''){
$csize =" ";
}
if ($cdescription ==''){
$cdescription =" ";
} else {
$cdescription = str_replace("'","''",$cdescription);
}
if (isset($_FILES)){
@list(,,$imgtype,) = getimagesize($_FILES,);
if ($imgtype == 3)
$ect = "png";
elseif ($imgtype == 2)
$ext = "jpeg";
elseif ($imgtype == 1)
$ext ="gif";
else
header ('location: http://www.kambuja-designs.com/uploaderror.php?errortitle=Error!&errormsg=File not support!');
$content = file_get_contents($_FILES);
$content = mysql_real_escape_string($content);
}
$dbh = mysql_connect($hostname, $username, $password) or die("Could not connect to server");
$selected = mysql_select_db("hanum3_Kambuja",$dbh) or die("Could not connect to server");
if (mysql_query("Insert into TblClothes(ClothesName,Description,Colour,CSize,Price,Category,Picture) values('".$cname."','".$cdescription."','".$ccolour."','".$ccsize."',".$cprice.",'".$ccategory."','".$content."')")) {
header ('location: http://www.kambuja-designs.com/uploaderror.php?errortitle=Upload Successfull!&errormsg= ');
} else {
header ('location: http://www.kambuja-designs.com/uploaderror.php?errortitle=Upload Unsuccessfull!&errormsg=Please check your filed again!');
}
mysql_close($dbh);
?>
===========================================================
uploaderror.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Test PHP</title>
</head>
<body>
<div id="Layer1" style="position:absolute; width:445px; height:73px; z-index:1; left: 432px; top: 126px; background-color: #CCCCCC; layer-background-color: #CCCCCC; border: 1px none #000000;">
<form action="upload.htm">
<table width="439" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="8"> </td>
<td width="431"><span class="style9">
<?
$errortitle = $_REQUEST["errortitle"];
if ($errortitle ==''){
echo " ";
} else {
echo $errortitle;
}
?>
</span></td>
</tr>
<tr>
<td> </td>
<td><span class="style10">
<?
$errormsg = $_REQUEST["errormsg"];
if ($errormsg ==''){
echo " ";
} else {
echo $errormsg;
}
?>
</span></td>
</tr>
<tr valign="bottom">
<td height="30" colspan="2"><p align="center">
<input type="submit" value=" Back ">
</p></td>
</tr>
</table>
</form>
</div>
<table width="770" height="444" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="770" height="444"> </td>
</tr>
</table>
</body>
</html>
Thanks in advance