如何添加图像到mysql数据库,当用户提交他们的图像


how to add images to mysql database when a user submit their images

我想添加多个图像到mysql数据库使用的形式。每当用户提交表单时,它就会捕获所有数据并将其存储到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=49 ;

我的html表单是这样的

<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>&nbsp;</td>
    <td><input type="submit" name="submit" id="submit" value="Submit" /></td>
  </tr>
</form>
</table>

PHP中的处理表单是这样的

<?
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>Success.</h2>";
   mysql_close($con);
}
 ?>

我的问题是当我从mysql数据库插入图像时,它成功地存储。但当我这样做,从我的HTML表单它不存储图像。它只存储数据(文本)。

我不知道我的表单中到底是什么错误

我想知道使用htmlspecialchars()二进制数据会做什么。

$users_image_one = htmlspecialchars($users_image_one);
$users_image_two = htmlspecialchars($users_image_two);
(编辑:)

htmlspecialchars()用于保留文本数据的特殊字符。但是,如果您将它用于二进制数据,则会把所有内容弄乱。

自行排除故障:

你可以试着找出问题,首先只上传图片。

也可以看看这个链接:使用POST方法上传文件

听起来不像有错误. . . .

在数据库中不存储实际的图像,而只是存储它们的名称或对图像的引用

。product_one.jpg

当你想显示它的时候你可以这样做

<img src=" <?php $echo 'images'$users_image_one ?> ">